设置背景图像警报对话框 [英] set background image alertdialog
本文介绍了设置背景图像警报对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Buttons
和RadioGroup
创建自定义的AlertDialog
.我想为此AlertDialog
将背景图像保存在我的可绘制对象中.
I am trying to create a customized AlertDialog
with Buttons
and RadioGroup
. I want to have a background image saved in my drawable for this AlertDialog
.
AlertDialog.Builder alert = new AlertDialog.Builder(AutoGenerate.this);
alert.setTitle("Select color");
还有像alert.setbackgrounddrawable(R.drawable.img)
这样的其他选择吗?
Is there any alternative option like alert.setbackgrounddrawable(R.drawable.img)
?
推荐答案
带有自定义视图的自定义对话框.
Custom dialog with custom view.
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
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();
}
这篇关于设置背景图像警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文