Reputation: 4400
I have been trying to set a custom AlertDialog but was not able to get correctly.
prompt.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffe3e3"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="HardcodedText">
<TextView
android:id="@+id/prompttitile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|left"
android:padding="5dp"
android:text="Error Title Here"
android:textColor="#c50200"
android:textSize="16sp"
android:textStyle="normal"
android:visibility="visible"
/>
<TextView
android:id="@+id/promptmessage"
android:layout_below="@+id/prompttitile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:padding="5dp"
android:text="Error Title Here"
android:textColor="#c50200"
android:textSize="16sp"
android:textStyle="normal" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/promptmessage"
android:weightSum="2"
android:padding="10dp"
android:background="#333"
>
<Button
android:text="@android:string/no"
android:id="@+id/promptno"
android:layout_width="0sp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:padding="7dp"
android:textColor="@android:color/black"
android:textSize="14sp"
android:textStyle="bold"
android:background="@drawable/button_selector"
android:layout_marginRight="5dp"
android:gravity="center"
/>
<Button
android:text="@android:string/ok"
android:id="@+id/promptok"
android:layout_width="0sp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:padding="7dp"
android:textColor="@android:color/black"
android:textSize="14sp"
android:textStyle="bold"
android:background="@drawable/button_selector"
android:gravity="center"
/>
</LinearLayout>
</RelativeLayout>
I am getting black color background at the top of the AlertDialog and I want to only the AlertDialog to be displayed.
Dialog code
Dialog d=new Dialog(mContext);
d.setContentView(R.layout.prompt);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
d.getWindow().setAttributes(lp);
d.show();
Upvotes: 0
Views: 866
Reputation: 5391
Dialog d=new Dialog(this);
//Add this
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(R.layout.prompt);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
d.getWindow().setAttributes(lp);
d.show();
Upvotes: 1
Reputation: 1703
Try this
Dialog dialog = new Dialog(MainAppActivity.this, R.style.PauseDialog);
dialog.setContentView(R.layout.prompt);
dialog.setCancelable(true);
dialog.show();
and in style.xml
<style name="PauseDialog" parent="@android:style/Theme.Translucent.NoTitleBar"></style>
Upvotes: 1