我一直在嘗試設置自定義AlertDialog但無法正確獲取。無法正確定製AlertDialog
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>
我得到黑色背景在AlertDialog的頂部,我想只是要顯示的AlertDialog。
對話框代碼
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();
你是如何創建的代碼的對話框?請發佈,也... – Anukool 2013-02-15 11:21:18
好吧,我已經粘貼對話框代碼.. @Anukool – 2013-02-15 11:26:15
檢查答案。 – Anukool 2013-02-15 11:30:46