Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为警报对话框中的按钮设置可绘图项?在Android中_Android_Android Alertdialog_Android Dialogfragment_Android Dialog - Fatal编程技术网

如何为警报对话框中的按钮设置可绘图项?在Android中

如何为警报对话框中的按钮设置可绘图项?在Android中,android,android-alertdialog,android-dialogfragment,android-dialog,Android,Android Alertdialog,Android Dialogfragment,Android Dialog,我想在警报对话框中设置一个图像和两个按钮,我已经尝试了下面的代码,我可以设置图像,但我不知道如何设置按钮的图标。我还想对齐另一个按钮底部的第一个按钮,如此屏幕截图 我已尝试使用此代码添加图像 public void showAlert() { AlertDialog.Builder alertadd = new AlertDialog.Builder( MainActivity.this); LayoutInflater factory = LayoutInflater.f

我想在警报对话框中设置一个图像和两个按钮,我已经尝试了下面的代码,我可以设置图像,但我不知道如何设置按钮的图标。我还想对齐另一个按钮底部的第一个按钮,如此屏幕截图

我已尝试使用此代码添加图像

 public void showAlert()
 {
AlertDialog.Builder alertadd = new AlertDialog.Builder(
        MainActivity.this);

LayoutInflater factory = LayoutInflater.from(MainActivity.this);
final View view = factory.inflate(R.layout.alertimage, null);
alertadd.setView(view);
alertadd.setNeutralButton("Here!", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dlg, int sumthin) {

    }
});

alertadd.show();
}

在XML布局文件中尝试以下操作:

<Button
...
android:drawableLeft="@drawable/source" />

我建议您创建您想要的布局(R.layout.alertimage),图像和按钮已经在里面,然后将其充气到对话框中(不要使用警报对话框按钮)。
然后你可以使用alertadd.findviewbyid(R.id.button)。setonclicklistener(…)

我已经用一个简单的弹出窗口解决了这个问题。它工作得很好。

尝试为对话框片段创建自定义类,并将其设置在上面,或者你可以为对话框创建主题,如图所示,以创建自定义对话框明白你的意思吗,弹出窗口?您能举个例子吗?在您的情况下,在
alertAdd.show()之后执行类似操作
Button neutralButton=alertAdd.getButton(DialogInterface.Button\u NEUTRAL);neutralButton.SetCompoundDrawableSwithinInstincBounds(R.drawable.source,0,0,0)
mButton.setCompoundDrawablesWithIntrinsicBounds( R.drawable.source, 0, 0, 0);