android setNegativeButton到自定义对话框
我有自己的自定义对话框,如下所示:android setNegativeButton到自定义对话框,android,android-alertdialog,android-dialog,Android,Android Alertdialog,Android Dialog,我有自己的自定义对话框,如下所示: public class BerekenDialog extends Dialog{ public BerekenDialog(Context context) { super(context); setContentView(R.layout.bereken_dialog_layout); this.setTitle("Bereken"); //dostuff. } } 我用
public class BerekenDialog extends Dialog{
public BerekenDialog(Context context) {
super(context);
setContentView(R.layout.bereken_dialog_layout);
this.setTitle("Bereken");
//dostuff.
}
}
我用以下命令启动对话框:
BerekenDialog bd = new BerekenDialog (this);
bd.show();
有没有办法将alertdialog中的负、正和中性按钮添加到我的自定义对话框中
get data from some spinners, make a calculation with the data and display it
无需创建自定义对话框即可完成此操作,只有在构建器中创建对话框时,才会创建正按钮和负按钮。没有办法实现它,相反,您可以使用按钮在xml布局中创建自己的
在不使用自定义对话框的情况下创建alertdialog:
AlertDialog a = new AlertDialog.Builder(this)
.setTitle("Bereken")
.setView(getLayoutInflater().inflate( R.layout.bereken_dialog_layout,null))
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// ok button
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// cancel button
}
}).create();
TextView tv = (TextView)a.findViewById(r.id.your_id); //use the instance of textview from layout of dialog
tv.setText("update"); //set is before displaying
a.show();
您可以添加两个按钮,使它们看起来像AlerDialog.Builder中的按钮 创建这两个按钮时,只需更改其背景色并在其周围添加一些边框。这可以通过创建可绘制(按钮\边框\形状)来完成:
只需添加您想要的按钮
R.layout.bereken\u dialog\u layout.xml
?发布bereken\u dialog\u布局。xml@codeMagic我不是说普通的纽扣。我说的是这张图片中的按钮:这些按钮有什么不“常规”的地方?@tyczj这把按钮放在按钮上,你知道如何添加小线条和onclick颜色吗?
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp" android:color="#bdbdbd" />
<solid android:color="#f2f2f2" />
</shape>
android:background="@drawable/button_border_shape"