这个问题出现在使用自定义布局的AlertDialog时,在标题和按钮的后面会出现一些无法点击的空白区域。可以通过在自定义布局的根布局中添加如下属性来解决这个问题:
android:paddingLeft="0dp" android:paddingTop="0dp" android:paddingRight="0dp" android:paddingBottom="0dp" android:layout_marginLeft="0dp" android:layout_marginTop="0dp" android:layout_marginRight="0dp" android:layout_marginBottom="0dp"
例如,假设我们有一个自定义布局布局文件名为custom_layout.xml:
然后在代码中使用如下方式创建AlertDialog:
AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.custom_layout, null); builder.setView(view); // 设置标题、按钮等 AlertDialog dialog = builder.create(); dialog.show();
下一篇:AlertDialog不断崩溃