我们可以在Android警报对话框中使用垂直按钮吗?

默认情况下,我们在警告对话框中获得两个或三个水平对齐的按钮.是否可以在警报对话框中将它们垂直对齐?

解决方法

当然,您可以使用Dialog.setContentView()将对话框的内容设置为任意布局.
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.yourLayoutId);
dialog.show();

使用包含所需按钮的Vertical LinearLayout创建一个布局文件,并在对话框中调用setContentView(),传递布局文件的名称.

如果你在AlertDialog上没用,你可以用builder.setView()做类似的事情.

LayoutInflater inflater = (LayoutInflater) 
        getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.yourLayoutId,(ViewGroup) findViewById(R.id.yourLayoutRoot));
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setView(layout);
AlertDialog alertDialog = builder.create();
alertDialog.show();

相关文章

Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...
Android实现自定义带文字和图片的Button 在Android开发中经常...
Android 关于长按back键退出应用程序的实现最近在做一个Andr...
android自带的时间选择器只能精确到分,但是对于某些应用要求...