I have a dialog with custom layout, everything is working fine, except there is a big empty spaces at the bottom which i cannot remove.
Any suggestion how i can remove that empty space.
Here is my Code:
public Dialog onCreateDialog() {
final AlertDialog.Builder builder = new AlertDialog.Builder(
this);
// Get the layout inflater
LayoutInflater inflater = getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.dialogue_cover_staying, null))
// Add action buttons
.setPositiveButton("Done", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
//action
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
return builder.show();
}
My XML Layout:
`
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back1"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_weight="0.00"
android:background="#drawable/box"
android:gravity="center_vertical"
android:text="Enter Covers and Guest Type"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/et_covers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="35dp"
android:fontFamily="sans-serif"
android:hint="Covers"
android:inputType="number" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:fontFamily="sans-serif"
android:text="Staying Guest...?"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp" >
<CheckBox
android:id="#+id/checkYes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="YES" />
<CheckBox
android:id="#+id/checkNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:text="NO" />
</LinearLayout>
</LinearLayout> `
Change your layout width and height from "wrap_content" to "100dp" for example..like this..
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="200dp"
android:background="#drawable/back1"
android:orientation="vertical" >
Moreover you can set minWidth and minHeight..
android:minWidth="300dp"
android:minHeight="400dp"
Related
I have implemented a Custom Dialog with Relative layout as Parent.. The issue is that the layout height goes match_parent size even i use wrap_content on Relative Layout...................................................................................................................................
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/layoutPopup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="Standered Delvery"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="18dp"
/>
<TextView
android:id="#+id/item_count_popup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="6 Items"
android:textAlignment="center" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/bg_ash"
>
</View>
<ListView
android:id="#+id/listview_popup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp">
</ListView>
</LinearLayout>
<TextView
android:id="#+id/popup_dismiss_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:text="DISMISS"
android:textColor="#color/orange"
/>
This is the java code
totalCountTxt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
customDialog = new Dialog(mContext);
customDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
customDialog.setContentView(R.layout.popup_item_details_delvery_options);
customDialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
ListView listView=(ListView)customDialog.findViewById(R.id.listview_popup) ;
TextView count=(TextView)customDialog.findViewById(R.id.item_count_popup);
count.setText(String.valueOf(arrayListCartModel.get(0).getItemCount())+" Items");
PopupDelveryOptionsAdapter adapter=new PopupDelveryOptionsAdapter(mContext,arrayListCartModel);
listView.setAdapter(adapter);
customDialog.show();
}
});
Screenshot for a reference
Does Anyone have the answer
Try using AlertBuilder
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(context, style_to_be_use));
view = inflater.inflate(your_layoutID,null);
alertDialog.setView(view);
alertDialog.setTitle("your title");
alertDialog.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
//function body
});
alertDialog.create();
alertDialog.show();
Replace your TextView with this
<TextView
android:id="#+id/popup_dismiss_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/layout_popup"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:text="DISMISS"
android:textColor="#color/orange"
/>
Use Linear Layout as a parent layout instead of RelativeLayout
I am developing app having a popup window showing successfully but button inside is not working. When the button is click the event is not listening. The code is shown below.
private void showPopup() {
//LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View customView = inflater.inflate(R.layout.popup_layout,null);
mPopupWindow = new PopupWindow(
customView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
Button btn_popup_submit = (Button)customView.findViewById(R.id.btn_popup_submit);
Button btn_popup_cancel = (Button)customView.findViewById(R.id.btn_popup_cancel);
btn_popup_submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "aaa", Toast.LENGTH_SHORT).show();
Log.d("LOG","aaaa");
}
});
btn_popup_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "bbbb", Toast.LENGTH_SHORT).show();
Log.d("LOG","bbbb");
}
});
if(Build.VERSION.SDK_INT>=21){
mPopupWindow.setElevation(5.0f);//5.0f
}
mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);
mPopupWindow.setFocusable(true);
mPopupWindow.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(mContext, android.R.color.transparent)));
mPopupWindow.setOutsideTouchable(false);
mPopupWindow.setTouchable(false);
mPopupWindow.update();
}
The pop up layout code is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_custom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
android:background="#5b5e93"
>
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email Sent."
android:textSize="20sp"
android:textColor="#color/colorWhite"
android:padding="25sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_above="#+id/editText"
android:layout_marginBottom="50dp"
android:background="#color/colorGray"
android:orientation="horizontal"></LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/tv"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:textSize="16sp"
android:textColor="#color/colorWhite"
android:text="#string/email_sent" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:ems="4"
android:maxLength="4"
android:minLines="4"
android:inputType="number" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/btn_popup_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/buttoncolor"
android:text="Submit"
android:textAllCaps="false" />
<Button
android:id="#+id/btn_popup_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/buttoncolor"
android:text="Cancel"
android:textAllCaps="false" />
</LinearLayout>
</RelativeLayout>
The button names are btn_popup_submit and btn_popup_cancel.
I tried different methods but the problem. I don't know where is the problem facing. Please help me thanks.
Replace this line of code.Allow popWindow Touch.
mPopupWindow.setTouchable(false);
to
mPopupWindow.setTouchable(true);
I'm having trouble with the message of a dialog.
Everything works fine until I want to type information in the edittext and the keyboard pops up - then the second (and last) line of the message of the dialog is cut to half..
Looks dialog looks like
Icon and Title:
Message line 1
Message line 2 (<- half visibile with keyboard)
ScrollView with some edittexts
Negative button | Positive button
Edit: Code
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
View viewGroup = inflater.inflate(R.layout.layout_dialog_daily_report, null);
ScrollView layout = (ScrollView) viewGroup.findViewById(R.id.dialog_parent);
final EditText 1 = (EditText) viewGroup.findViewById(R.id.dialog_1);
final EditText 2 = (EditText) viewGroup.findViewById(R.id.dialog_2);
final EditText 3 = (EditText) viewGroup.findViewById(R.id.dialog_3);
final EditText 4 = (EditText) viewGroup.findViewById(R.id.dialog_4);
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setIcon(R.drawable.icon);
builder.setTitle(R.string.dialog_title);
builder.setMessage(R.string.dialog_message);
builder.setView(layout);
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
dialog.show();
Layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dialog_parent"
android:margin="7dp"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ellipsize="end"
android:text="#string/dialog_1" />
<EditText
android:id="#+id/dialog_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ellipsize="end"
android:text="#string/dialog_2" />
<EditText
android:id="#+id/dialog_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ellipsize="end"
android:text="#string/dialog_3" />
<EditText
android:id="#+id/dialog_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:ellipsize="end"
android:text="#string/dialog_4" />
<EditText
android:id="#+id/dialog_4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4" />
</LinearLayout>
</LinearLayout>
As you can see the buttons are not visible, I dont know why the scrollview isnt scrollable anymore
How can I prevent that the Dialog.setMessage text is cut off on showing the keyboard?
add next line into your Manifest:
android:windowSoftInputMode="adjustResize"
I believe the errors are mostly in xml,try removing android:elipsize,maybe giving the layout_width's a value other that 0,you can try
In my android app i need to use alertdialog programmatically with two images in first row and another two images in second row. i seen some example like,
CharSequence colors[] = new CharSequence[] {"red", "green", "blue", "black"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setItems(colors, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// the user clicked on colors[which]
}
});
builder.show();
in the above example have only one option for every row like red in first row, green in next row, blue in third row like that. I need to implement 2 option in every row, pls guide me,,
Dialog mDialog;
mDialog=new Dialog(SplashScreen.this);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(R.layout.yourcustomlayout);
TextView ok,cancel;
ok=(TextView) mDialog.findViewById(R.id.dialogyes);
cancel=(TextView) mDialog.findViewById(R.id.dialogno);
ok.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
mDialog.cancel();
}
});
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
finish();
mDialog.cancel();
}
});
mDialog.show();
yourcustomlayout.xml -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white" >
<TextView
android:id="#+id/dialogtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Internet Connection"
android:textAppearance="#android:style/TextAppearance.Medium"
android:textColor="#android:color/black" />
<View
android:id="#+id/view1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/dialogtitle"
android:layout_marginTop="25dp"
android:background="#C83437" />
<TextView
android:id="#+id/dialogMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/view1"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="You are not connected to internet.\nDo you want to on connection?"
android:textAppearance="#android:style/TextAppearance.Medium"
android:textColor="#android:color/black" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="150dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:id="#+id/dialogyes"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginBottom="10dp"
android:layout_weight="0.5"
android:gravity="center"
android:text="YES"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/dialogno"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginBottom="10dp"
android:layout_weight="0.5"
android:gravity="center"
android:text="NO"
android:textColor="#android:color/black" />
</LinearLayout>
</RelativeLayout>
in mDialog.setContentView() add your custom layout.
I am trying to customize my alert dialog with a layout. The problem is that the ALert dialog box is lunched with small size and most of the layout is trancated or words are overlapping. It is not screen issue as the dialog box is very small and does not seem to expand to cover all the contents. Why do you think this is happening?
I am using the following layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout1"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvNa"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"/>
<EditText
android:id="#+id/etNa"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvQ"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"/>
<EditText
android:id="#+id/etQ"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/linearLayout1"
android:layout_centerVertical="true"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvP"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
<EditText
android:id="#+id/etP"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal" />
</LinearLayout>
</RelativeLayout>
And I am using the following code:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.add_dialog, null);
alert.setView(layout);
alert.setTitle("New one");
alert.setPositiveButton("Ok",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.show();
The Dialog Object has a set max size that you have not over written. You could add your layout to a ScrollView. Other than that you will have to follow the inheritances of the Dialog until you find where the max Dialog size is being set and override this. GrepCode is a good place to view the SDK source.