设置背景图像alertdialog
我想创建一个定制的AlertDialog
与Buttons
和RadioGroup
。我想在这个AlertDialog
的抽屉中保存背景图片。设置背景图像alertdialog
AlertDialog.Builder alert = new AlertDialog.Builder(AutoGenerate.this);
alert.setTitle("Select color");
有没有像alert.setbackgrounddrawable(R.drawable.img)
任何替代方案?
自定义对话框提醒对话框。
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();
}
你好,谢谢你的答复,我使用这个警报dialod弹出一个单选按钮的点击监听器,当试图插入radiobutton.setonclicklistener内的代码,获取classcast异常,任何想法? – bharath 2013-03-20 10:09:22
可以发布代码。 – Raghunandan 2013-03-20 10:10:47
如果(selected_option.equals( “否”)|| selected_option.equals( “否”)|| selected_option.equals( “无”)) \t \t \t \t \t { \t \t \t \t \t \t LayoutInflater充气= getLayoutInflater (); \t \t \t \t \t \t查看dialoglayout = inflater.inflate(R.layout.customdialog,(ViewGroup)getCurrentFocus()); \t \t \t \t \t \t final CharSequence [] gender = {“Male”,“Female”}; \t \t \t \t \t \t \t \t \t \t \t对话框d =新对话框(自动生成。这个); \t \t \t \t \t d.requestWindowFeature(Window.FEATURE_NO_TITLE); \t \t \t \t \t d.setContentView(R.layout.customdialog); //定制对话框的布局。 \t \t \t \t \t Button thankyou =(Button)d.findViewById(R.id.thankyou); \t \t \t \t \t d.show(); \t \t \t \t \t} – bharath 2013-03-20 10:16:29
,你可以做,使用版式文件。检查下面的代码
LayoutInflater inflater = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialoglayout = inflater.inflate(R.layout.dialog_layout, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialoglayout);
builder.show();
dialog_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
</LinearLayout>
您也可以在XML中使用不同势的看法。
嗨谢谢回复,得到classcast异常做它,任何想法? – bharath 2013-03-20 10:02:50
just cheange this line ---> LayoutInflater inflater =(LayoutInflater)this \t \t \t \t .getSystemService(Context.LAYOUT_INFLATER_SERVICE); – 2013-03-20 10:25:18
检查我编辑的答案.. – 2013-03-20 10:25:34
您可以使用自定义视图创建自定义对话框。 – yahya 2013-03-20 09:52:06
可能的重复项:[one](http://*.com/q/5473058/420015)[two](http://*.com/questions/7281963/how-to-change-the-background-image-警告对话框)[三](http://*.com/questions/10347545/android-change-custom-alertdialog-background) – adneal 2013-03-20 09:53:49
你想在你的自定义警报对话框中设置背景是这样吗? – GrIsHu 2013-03-20 09:58:17