Reputation: 668
I'm working with custom alertDialog in android and found a problem. My code is simple:
LayoutInflater inflatre = getLayoutInflater();
View v = inflatre.inflate(R.layout.dialog_view, null);
AlertDialog.Builder dialog = new AlertDialog.Builder(EditPageActivity.this);
dialog.setView(v);
dialog.show();
And the layout xml is:
<?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="match_parent"
android:background="@color/bg"
android:padding="10dp"
android:gravity="center" >
<Button
android:id="@+id/gallery_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gallery" />
<Button
android:id="@+id/photo_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/gallery_b"
android:text="Take Photo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/gallery_b"
android:layout_centerHorizontal="true"
android:text="Choose Image"
android:textSize="20sp"
android:textColor="@color/splash_font"
android:layout_marginBottom="10dp" />
But the output is like this:
Feeling helpless after searching google :(...can anyone describe me anything
Upvotes: 0
Views: 131
Reputation: 52790
//Try this one:
final Dialog dialog = new Dialog(mContext);
dialog.requestWindowFeature((int) Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.your_layout_here);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialog.getWindow().setAttributes(lp);
dialog.show();
Upvotes: 1
Reputation: 4522
Try this layout for Dialog
, It should work.
<?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="match_parent"
android:background="@color/bg"
android:padding="10dp"
android:gravity="center">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Choose Image"
android:textSize="20sp"
android:textColor="@color/splash_font"/>
<Button
android:id="@+id/gallery_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:text="Gallery"
android:layout_marginTop="10dp"/>
<Button
android:id="@+id/photo_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/gallery_b"
android:text="Take Photo" />
</RelativeLayout>
Upvotes: 1
Reputation: 2198
Try this
Dialog dialog = new Dialog(YourActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.yourlayout); // your layout id
Button dialogButton = (Button) dialog
.findViewById(R.id.dialogButtonOK); // button in your layout
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
dialog.show();
Upvotes: 1