自定義對話框提醒對話框。
Dialog d = new Dialog(AutoGenerate.this);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(R.layout.alertdialog);// custom layour for dialog.
Button thankyou = (Button) d.findViewById(R.id.thankyou);
d.show();
alertdialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/dialog_layout_root"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical"
android:padding="10dp"
>
<Button
android:id="@+id/thankyou"
android:layout_width="100dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:text="hello"
android:padding="5dp">
</Button>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
編輯:
rb= (RadioButton) findViewById(R.id.radioButton1);
rb.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showAlertDialog();
}
});
public void showAlertDialog() {
final Dialog d = new Dialog(MainActivity.this);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(R.layout.alertdialog);
// Thank you Button Listener.
final TextView tv = (TextView) d.findViewById(R.id.textView1);
final Button thankyou = (Button) d.findViewById(R.id.thankyou);
thankyou.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
// TODO Auto-generated method stub
tv.setText("Button Clicked");
return true;
}
});
d.show();
}
您可以使用自定義視圖創建自定義對話框。 – yahya 2013-03-20 09:52:06
可能的重複項:[one](http://stackoverflow.com/q/5473058/420015)[two](http://stackoverflow.com/questions/7281963/how-to-change-the-background-image-警告對話框)[三](http://stackoverflow.com/questions/10347545/android-change-custom-alertdialog-background) – adneal 2013-03-20 09:53:49
你想在你的自定義警報對話框中設置背景是這樣嗎? – GrIsHu 2013-03-20 09:58:17