我打算用 layout_weight=1 创建 3 个按钮,对自定义对话框不感兴趣。所以我写了下面的代码。它不起作用。总是是按钮给我 null。这段代码有什么问题?
AlertDialog dialog= new AlertDialog.Builder(this).create();
dialog.setIcon(R.drawable.alert_icon);
dialog.setTitle("title");
dialog.setMessage("Message");
dialog.setButton(AlertDialog.BUTTON_POSITIVE,"Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
Button yesButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
Log.w("Button",""+yesButton);//here getting null
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1f);
yesButton.setLayoutParams(layoutParams);
dialog.show();
问候,Android 开发者。