I have a pop up that displays an image upon clicking a button. I got to display the pop up but the image is so small and I want it to occupy the 90% of the screen and add a close button to it.
Here is my code:
PopupWindow popUp;
LinearLayout layout;
TextView tv;
LayoutParams params;
ImageView imageView;
boolean click = true;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bmi);
popUp = new PopupWindow(this);
layout = new LinearLayout(this);
tv = new TextView(this);
imageView = new ImageView(this);
imageView.setImageResource(R.drawable.animalbite);
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int fullScreenWidth = display.getWidth();
int dialogWidth = (int) (fullScreenWidth * 0.9);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.height = LayoutParams.WRAP_CONTENT;
params.width = dialogWidth;
getWindow().setAttributes(params);
imageView.setLayoutParams(params);
//tv.setText("Hi this is a sample text for popup window");
layout.addView(imageView, params);
popUp.setContentView(layout);
Button ViewBmi = (Button) findViewById(R.id.ViewBmi);
ViewBmi.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (click) {
popUp.showAtLocation(layout, Gravity.CENTER, 10 ,10);
click = false;
} else {
popUp.dismiss();
click = true;
}
}
});
}
Here is the display:
ANy ideas?
Try this...
PopupWindow popUp;
LinearLayout layout;
TextView tv;
LayoutParams params,params2;
ImageView imageView;
boolean click = true;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Display display = getWindowManager().getDefaultDisplay();
final int height = (display.getHeight()*90)/100;
final int width = (display.getWidth()*90)/100;
popUp = new PopupWindow(this);
layout = new LinearLayout(this);
tv = new TextView(this);
imageView = new ImageView(this);
imageView.setImageResource(R.drawable.ic_launcher);
params = new LayoutParams(width,height-50);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(imageView, params);
Button button = new Button(this);
button.setText("Close");
params2 = new LayoutParams(100,50);
layout.addView(button,params2);
popUp.setContentView(layout);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
popUp.dismiss();
click = true;
}
});
Button ViewBmi = (Button) findViewById(R.id.button1);
ViewBmi.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (click) {
popUp.showAtLocation(layout, Gravity.CENTER, 10, 10);
popUp.update(10, 20, width,height);
click = false;
} else {
popUp.dismiss();
click = true;
}
}
});
}
Try This....
Button button = new Button(this);
button.setText("Close");
params2 = new LayoutParams(100,50);
--->params2.setMargins(100, 0, 0, 0);
layout.addView(button,params2);
I'd do it like this:
height = (int)(0.9*getWindow().getWindowManager().getDefaultDisplay().getHeight());
params.height = height;
Try:
params = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
...
layout.addView(imageView, params);
This way the ImageView will be as wide, as possible.
If the underlying dialog is not wide enough, then you can set it's width also full screen:
WindowManager.LayoutParams params = getWindow().getAttributes();
params.height = LayoutParams.WRAP_CONTENT;
params.width = LayoutParams.MATCH_PARENT;
getWindow().setAttributes(params);
Or if you want it to be for example 90% of the screen, then:
// get the width of the whole screen
Display display = getWindow().getDefaultDisplay();
int fullScreenWidth = display.getWidth();
//then set 90% of it to the width of the Dialog:
int dialogWidth = (int) fullScreenWidth * 0.9);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.height = LayoutParams.WRAP_CONTENT;
params.width = dialogWidth;
getWindow().setAttributes(params);
Related
I want to add buttons dynamically according to diffrent screen sizes. How can I achive it.
This is what I have tried. But when I change the first button from WRAP_CONTENT to static height, width none of the button is shown on the screen
public void setButtons(){
// button one params
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(380,433,10,20);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(getMyNewX(76),getMyNewX(76));
params1.setMargins(229,-45,50,20);
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(getMyNewX(76),getMyNewX(76));
params2.setMargins(239,60,10,20);
LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(getMyNewX(76),getMyNewX(76));
params3.setMargins(422,-45,10,20);
LinearLayout.LayoutParams params4 = new LinearLayout.LayoutParams(getMyNewX(76),getMyNewX(76));
params4.setMargins(592,-455,10,20);
LinearLayout.LayoutParams params5 = new LinearLayout.LayoutParams(getMyNewX(76),getMyNewX(76));
params5.setMargins(592,65,10,20);
// LinearLayout.LayoutParams params6 = new LinearLayout.LayoutParams(76,76);
// params6.setMargins(592,-275,10,20);
LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(params);
Button button1 = new Button(getApplicationContext());
button1.setLayoutParams(params);
// button1.setText("like");
button1.setBackgroundDrawable(getResources().getDrawable(R.drawable.like));
// button1.setBackgroundColor(Color.TRANSPARENT);
Button button2 = new Button(getApplicationContext());
button2.setLayoutParams(params1);
// button2.setText("share");
button2.setBackgroundDrawable(getResources().getDrawable(R.drawable.share));
// button2.setBackgroundColor(Color.TRANSPARENT);
Button button3 = new Button(getApplicationContext());
button3.setLayoutParams(params2);
// button3.setText("mute");
button3.setBackgroundDrawable(getResources().getDrawable(R.drawable.mute));
// button3.setBackgroundColor(Color.TRANSPARENT);
Button button4 = new Button(getApplicationContext());
button4.setLayoutParams(params3);
button4.setBackgroundDrawable(getResources().getDrawable(R.drawable.download));
Button button5 = new Button(getApplicationContext());
button5.setLayoutParams(params4);
button5.setBackgroundColor(Color.TRANSPARENT);
Button button6 = new Button(getApplicationContext());
button6.setLayoutParams(params5);
button6.setBackgroundColor(Color.TRANSPARENT);
layout.addView(button1);
layout.addView(button2);
layout.addView(button3);
layout.addView(button4);
layout.addView(button5);
layout.addView(button6);
buttonLayout.addView(layout);
}
originalWidth = 1100;
originalHeight = 2050;
DisplayMetrics displayMetrics = getApplicationContext().getResources().getDisplayMetrics();
width = displayMetrics.widthPixels;
height = displayMetrics.heightPixels;
}
int getMyNewX(int originalX)
{
//originalX : x for line segment
return width/originalWidth * originalX;
}
int getMyNewY(int originalY)
{
//originalY : y for line segment
return height/originalHeight * originalY;
}
You can add weight dynamically this way
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
params.weight = 1.0f;
Button button = new Button(this);
button.setLayoutParams(params);
In Android studio
res -> values -> dimens.xml
declare your dimensions for devices below w820dp in dimens.xml file
dimension for devices w820dp and above in dimens.xml(w820dp) file
then use it in your code like
Android will automatically select required sizes for different resolutions
**w820dp - for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).**
this may also help you
There are two solution .
Solution 1:convert dp to pixel
private int convertPxToDp(int px){
return Math.round(px/(Resources.getSystem().getDisplayMetrics().xdpi /DisplayMetrics.DENSITY_DEFAULT));
}
Now you have dynamic value of pixel for all screen size.
Solution 2:Add weight to all your button
If it is vertical orientation then
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, 0);
else
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
0, LayoutParams.WRAP_CONTENT);
And then
params.weight = 1.0f;
Button button = new Button(this);
button.setLayoutParams(params);
You need to use layoutparams with weight property to fix width equally. Find below code.
private void initViews() {
lytButtons = (LinearLayout) findViewById(R.id.lytButtons);
btnAddButtons = (Button) findViewById(R.id.btnAddButtons);
btnAddButtons.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
addButtons();
}
});
}
protected void addButtons() {
try {
Button btn1 = createButton("Btn 1");
Button btn2 = createButton("Btn 2");
Button btn3 = createButton("Btn 3");
Button btn4 = createButton("Btn 4");
Button btn5 = createButton("Btn 5");
Button btn6 = createButton("Btn 6");
lytButtons.addView(btn1);
lytButtons.addView(btn2);
lytButtons.addView(btn3);
lytButtons.addView(btn4);
lytButtons.addView(btn5);
lytButtons.addView(btn6);
} catch (Exception e) {
e.printStackTrace();
}
}
Button createButton(String text) {
Button btn = new Button(getActivity());
btn.setText(text);
LinearLayout.LayoutParams prm1 = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
prm1.weight = 1.0f;
btn.setLayoutParams(prm1);
return btn;
}
I am trying to create a popup when clicking on ListView image with the same image just enlarged, this code works fine to me but I tried to position the View "vv" at the middle of the screen but the popup is still at (0,0)..
rowView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (!popu) {
View popupView = inflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
TextView txt = (TextView) popupView.findViewById(R.id.texttt);
ImageButton img = (ImageButton) popupView.findViewById(R.id.imgg);
txt.setText(imageId[position]);
img.setImageResource(imageId[position]);
View vv = new View(context);
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
vv.setX(width / 4);
vv.setY(height / 4);
img.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
popupWindow.dismiss();
popu = false;
}
});
popupWindow.showAsDropDown(vv, 50, -30);
popu = true;
}
}
});
I am not on an activity, it is my customadapter class..
EDIT:
Fixed, see Yasin KaƧmaz answer.
My code:
public class MyBottomDialog extends Dialog {
LinearLayout container;
public MyBottomDialog(Context context) {
super(context);
container = new LinearLayout(context);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
container.setLayoutParams(params);
container.setOrientation(LinearLayout.VERTICAL);
// container.setBackgroundColor(Color.TRANSPARENT);
int padding = context.getResources().getDimensionPixelSize(R.dimen.navigation_padding_bottom);
container.setPadding(padding, padding, padding, padding);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(container);
// setContentView(button);
setCancelable(true);
setCanceledOnTouchOutside(true);
getWindow().setGravity(Gravity.BOTTOM);
// getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
getWindow().setWindowAnimations(R.style.BottomDialogAnimation);
}
public void addMenuItems(String[] menuItemTitles, int[] menuItemTextColors) {
for (int i = 0; i < menuItemTitles.length; i++) {
// Button button = (Button) LayoutInflater.from(getContext()).inflate(R.layout.bottom_menu_item, container, false);
// button.setText(menuItemTitles[i]);
// button.setTextColor(menuItemTextColors[i]);
// container.addView(button);
addMenuItem(menuItemTitles[i], menuItemTextColors[i]);
}
}
public void addMenuItem(String menuItemTitle, int menuItemTextColor) {
// Button button = (Button) LayoutInflater.from(getContext()).inflate(R.layout.bottom_menu_item, container, false);
Button button = produceButton();
button.setText(menuItemTitle);
button.setTextColor(menuItemTextColor);
container.addView(button);
}
private Button produceButton() {
Button button = new Button(getContext());
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
button.setLayoutParams(params);
button.setGravity(Gravity.CENTER);
// button.setBackground(getContext().getResources().getDrawable(R.drawable.bottom_menu_button2));
float[] outerRadii = new float[]{24, 24, 24, 24, 24, 24, 24, 24};
RoundRectShape rect = new RoundRectShape(outerRadii, null, null);
ShapeDrawable drawable = new ShapeDrawable(rect);
drawable.getPaint().setColor(Color.WHITE);
drawable.getPaint().setStyle(Paint.Style.FILL);
button.setBackground(drawable);
return button;
}
}
then I use it:
MyBottomDialog dlg = new MyBottomDialog(this);
dlg.addMenuItems(new String[]{"delete", "cancel"}, new int[]{android.R.color.holo_red_light, android.R.color.holo_blue_light});
dialog.show();
but there is no any text in these two button in dialog, why?
i have created a layout programmatically and set it into secontentview within oncreate i am create chat layout using simple edittext and a send image button right from edittext whenever user click on edittext suddenly hide by softkeyboard i tried all option which is required to mention in menifest like adjustPan or screenresize etc but no effect the edittext still hidden by keyboard
here is my layout code that contain the edittext
private LinearLayout getTextChatViewTest() {
// MainActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// LibraryMainActivity.this.getActionBar().show();
LinearLayout linWrapperLayout;
LinearLayout.LayoutParams linWrapperLayoutParams;
LinearLayout linHeaderLayout;
LinearLayout.LayoutParams linHeaderParams;
TextView txtHeaderText;
linWrapperLayout = new LinearLayout(MainActivity.this);
linWrapperLayout.setOrientation(LinearLayout.VERTICAL);
linWrapperLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
linWrapperLayout.setLayoutParams(linWrapperLayoutParams);
linWrapperLayout.setBackgroundColor(Color.parseColor("#ffffff"));
linHeaderLayout = new LinearLayout(MainActivity.this);
linHeaderLayout.setBackgroundColor(Color.parseColor("#E3E9F3"));
linHeaderLayout.setPadding(pixToDp(10), pixToDp(5), pixToDp(10), pixToDp(5));
linHeaderParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
linHeaderLayout.setLayoutParams(linHeaderParams);
txtHeaderText = new TextView(MainActivity.this);
txtHeaderText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
txtHeaderText.setPadding(pixToDp(5), pixToDp(10), pixToDp(10), pixToDp(10));
txtHeaderText.setTextColor(Color.parseColor("#004A8F"));
linHeaderLayout.addView(txtHeaderText);
txtHeaderText.setText("Text Chat");
RelativeLayout rel = new RelativeLayout(MainActivity.this);
rel.setBackgroundColor(Color.parseColor("#ffffff"));
RelativeLayout.LayoutParams relPArams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
rel.setLayoutParams(relPArams);
linWrapperLayout.addView(rel);
rel.addView(linHeaderLayout);
txtChatArea = new TextView(MainActivity.this);
txtChatArea.setId(011);
txtChatArea.setBackgroundColor(Color.parseColor("#ffffff"));
txtChatArea.setGravity(Gravity.BOTTOM);
int scroll_amount = (int) (txtChatArea.getLineCount() * txtChatArea.getLineHeight()) - (txtChatArea.getBottom() - txtChatArea.getTop());
txtChatArea.setLinksClickable(true);
txtChatArea.setAutoLinkMask(Linkify.WEB_URLS);
txtChatArea.setText("Anything");
txtChatArea.scrollTo(0, scroll_amount);
txtChatArea.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17);
txtChatArea.setScrollY(0);
txtChatArea.setMovementMethod(new ScrollingMovementMethod());
/** for allowing copy from text chat area */
txtChatArea.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
txtChatArea.setCursorVisible(true);
return true;
}
});
// Button btn = new Button (this);
android.view.Display display = ((android.view.WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
// btn.setHeight((int)(display.getHeight()*0.68));
int height = display.getHeight();
RelativeLayout.LayoutParams relImageParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
(MainActivity.getPixelHeight(MainActivity.this))/2+60);
relImageParams.setMargins(pixToDp(15), pixToDp(100), pixToDp(15), 0);
relImageParams.addRule(RelativeLayout.BELOW, 111);
txtChatArea.setLayoutParams(relImageParams);
rel.addView(txtChatArea);
/* The following section was copied from incoming call view */
relIncomingBottomLayout = new RelativeLayout(MainActivity.this);
relIncomingBottomLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
relIncomingBottomLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
//relIncomingBottomLayoutParams.addRule(RelativeLayout.BELOW, 011);
relIncomingBottomLayoutParams.setMargins(pixToDp(10), 0, pixToDp(10), pixToDp(10));
relIncomingBottomLayout.setLayoutParams(relIncomingBottomLayoutParams);
rel.addView(relIncomingBottomLayout);
/* Now add a linearlayout with vertical orientation, which will contain two linearlayouts with horizontal orientation */
LinearLayout linBottomHolder = new LinearLayout(MainActivity.this);
linBottomHolder.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams linHolderParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
linBottomHolder.setLayoutParams(linHolderParams);
relIncomingBottomLayout.addView(linBottomHolder);
/* an warning view on characters left for end users */
txtWarning = new TextView(MainActivity.this);
txtWarning.setBackgroundColor(Color.parseColor("#ffffff"));
txtWarning.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
txtWarning.setText("150 characters left");
txtWarning.setTextColor(Color.GRAY);
linBottomHolder.addView(txtWarning);
/* Now add the first linear layout to contain an edittext to get message and an imageview */
LinearLayout linWriteHolder = new LinearLayout(MainActivity.this);
linWriteHolder.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams linWriteHolderPArams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
linWriteHolder.setLayoutParams(linWriteHolderPArams);
linBottomHolder.addView(linWriteHolder);
/* Now add an edittext and an imageview inside this linearlayout */
GradientDrawable gd = new GradientDrawable();
gd.setStroke(2, Color.parseColor("#E3E9F3"));
gd.setShape(GradientDrawable.RECTANGLE);
gd.setColor(Color.WHITE);
gd.setCornerRadius(5);
edtWriteMesage = new EditText(MainActivity.this);
edtWriteMesage.setHint("Type text here");
edtWriteMesage.setBackgroundColor(Color.parseColor("#ffffff"));
edtWriteMesage.setBackground(gd);
edtWriteMesage.setSingleLine(true);
/** filtering inputs */
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter.LengthFilter(150);
edtWriteMesage.setFilters(filters); /** now a maximum of 150 characters can be taken as input */
edtWriteMesage.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
int currentLength = edtWriteMesage.getText().toString().length();
int remainingLength = 150 - currentLength;
if(remainingLength <= 15){
txtWarning.setTextColor(Color.RED);
}else{
txtWarning.setTextColor(Color.GRAY);
}
txtWarning.setText(""+remainingLength + " characters left");
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void afterTextChanged(Editable s) {
}
});
LinearLayout.LayoutParams linWriteParams = new LinearLayout.LayoutParams(0,
ViewGroup.LayoutParams.WRAP_CONTENT, 0.9f);
linWriteParams.gravity = Gravity.CENTER_VERTICAL;
edtWriteMesage.setLayoutParams(linWriteParams);
linWriteHolder.addView(edtWriteMesage);
/* Now add an imageview with an arrow in it by the edittext's side */
imgSendArrow = new ImageView(MainActivity.this);
byte[] sendArrow = Base64.decode(SecondImageStore.send, Base64.DEFAULT);
//byte[] sendArrow = Base64.decode(SecondImageStore.papersend, Base64.DEFAULT);
imgSendArrow.setImageBitmap(BitmapFactory.decodeByteArray(sendArrow, 0, sendArrow.length));
LinearLayout.LayoutParams linSendParams = new LinearLayout.LayoutParams(0,
ViewGroup.LayoutParams.WRAP_CONTENT, 0.1f);
linSendParams.gravity = Gravity.CENTER;
linSendParams.setMargins(pxToDp(3), 0, pxToDp(2), 0);
imgSendArrow.setLayoutParams(linSendParams);
linWriteHolder.addView(imgSendArrow);
/* Now add the Second relative layout to contain two buttons */
LinearLayout linTextChatButtonHolder = new LinearLayout(MainActivity.this);
LinearLayout.LayoutParams linTextChatButtonHolderParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
linTextChatButtonHolderParams.setMargins(0, pixToDp(10), 0, 0);
linTextChatButtonHolder.setLayoutParams(linTextChatButtonHolderParams);
linBottomHolder.addView(linTextChatButtonHolder);
/* Button to end ongoing conference */
btnTextChatEndCall = new Button(MainActivity.this);
btnTextChatEndCall.setText("Call Held");
btnTextChatEndCall.setBackgroundColor(Color.parseColor("#C11E0F"));
btnTextChatEndCall.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
btnTextChatEndCall.setGravity(Gravity.CENTER);
btnTextChatEndCall.setTextColor(Color.parseColor("#ffffff"));
LinearLayout.LayoutParams linTextChatEndCallParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f);
linTextChatEndCallParams.setMargins(0, pixToDp(10), 0, 0);
btnTextChatEndCall.setLayoutParams(linTextChatEndCallParams);
linTextChatButtonHolder.addView(btnTextChatEndCall);
/* Button to display menu in chat mode */
btnTextChatMenu = new Button(MainActivity.this);
btnTextChatMenu.setText("Menu");
btnTextChatMenu.setGravity(Gravity.CENTER);
btnTextChatMenu.setBackgroundColor(Color.parseColor("#014A8E"));
btnTextChatMenu.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
btnTextChatMenu.setTextColor(Color.parseColor("#ffffff"));
LinearLayout.LayoutParams linTextChatMenuParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f);
linTextChatMenuParams.setMargins(pixToDp(10), pixToDp(10), 0, 0);
btnTextChatMenu.setLayoutParams(linTextChatMenuParams);
linTextChatButtonHolder.addView(btnTextChatMenu);
btnTextChatEndCall.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
try{
}catch(Exception e){
e.printStackTrace();
}
}
});
edtWriteMesage.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
int result = actionId & EditorInfo.IME_MASK_ACTION;
switch (result) {
case EditorInfo.IME_ACTION_DONE:
break;
case EditorInfo.IME_ACTION_NEXT:
break;
}
return false;
}
});
return linWrapperLayout;
// setContentView(linWrapperLayout);
}
Try on this way to hide keyboard
// Check if no view has focus:
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
In your Manifest.xml add this to you activity
<activity
android:windowSoftInputMode="adjustResize|stateHidden" ... >
...
</activity>
for Click here for more details about handling Input Methods
i have just remove getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); after that edittext comming below the edittext whenever soft keyboard appear
final Dialog dialog = new Dialog(MainScreenActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity_ana_ekran_dialog);
dialog.setCanceledOnTouchOutside(true);
Display display = getWindow().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
WindowManager.LayoutParams params = getWindow().getAttributes();
params.width = width * 90 / 100;
dialog.getWindow().setAttributes(params);
dialog.show();
This code is in onOptionsItemSelected section when i press action bar button my custome dialog doesn't appear.
My custom dialog doesn't appear when i set it's width?
I fix the problem this is the way i fix it...
Costume Dialog Class public class HarcamaKayitDialog extends Dialog implements android.view.View.OnClickListener.
Variables
Context ctx;
EditText yorum;
EditText harcama;
Button buttonTamamDialog;
Button buttonIptalDialog;
Dialog dialog;
Constractor
public HarcamaKayitDialog(Context context){
super(context);
this.ctx = context;
this.dialog = this;
}
onCreate.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_ana_ekran_alert_dialog);
Display display = getWindow().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
WindowManager.LayoutParams params = getWindow().getAttributes();
params.width = width * 90 / 100;
getWindow().setAttributes(params);
findViews();
}
onClick.
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.buttonTamam:
//transactions
dialog.dismiss();
break;
case R.id.buttonIptal:
dialog.dismiss();
break;
default:
break;
}
}
findViews function.
private void findViews() {
yorum = (EditText) findViewById(R.id.editTextYorum);
harcama = (EditText) findViewById(R.id.editTextHarcama);
buttonTamamDialog = (Button) findViewById(R.id.buttonTamam);
buttonIptalDialog = (Button) findViewById(R.id.buttonIptal);
buttonTamamDialog.setOnClickListener(this);
buttonIptalDialog.setOnClickListener(this);
}