【问题标题】:Android: Change custom AlertDialog backgroundAndroid:更改自定义 AlertDialog 背景
【发布时间】:2012-05-08 00:28:07
【问题描述】:

对话框布局xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/root_view"
     android:padding="3dp"
     android:background="@android:color/white"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" >

     //...content...

 </TableLayout>

点击图钉时地图叠加层中的对话框实现:

AlertDialog.Builder builder;

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.map_kap_dialog,
                    (ViewGroup) mapView.findViewById(R.id.root_view));

//prepare info to show...
//info prepared

//other preparations stuff
builder = new AlertDialog.Builder(context);
builder.setView(layout);
dialog = builder.create();
dialog.setInverseBackgroundForced(true);
dialog.setCanceledOnTouchOutside(true);
//show it
dialog.show();

以及我在测试时看到的:

所以我希望对话框周围的浅灰色背景(在方形空白区域周围)变为白色,这样看起来就不会那么难看。谁能帮帮我?

【问题讨论】:

    标签: java android android-alertdialog background-color


    【解决方案1】:

    我遇到了同样的问题,我设法使用这样的自定义对话框来解决它:

    public class CustomDialog extends Dialog {
        public CustomDialog(Context context, View view) {
            super(context);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(view);
            getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);
        }
    }
    

    【讨论】:

      【解决方案2】:

      嘿,将您的视图设置为构建器会在顶部底部创建这条灰线,而不是您可以将视图设置为您的对话框。像 dialog.setView(layout,0,0,0,0);它将您的布局绑定到整个对话框.

      【讨论】:

        【解决方案3】:

        另一种选择是从您的布局中删除android:background="@android:color/white"。然后警报对话框将统一具有其默认的浅灰色背景。 (因为您在黑暗主题上强制反转)至少它看起来不错并且值得麻烦。只是我的两分钱。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-06-27
          • 2013-07-27
          • 2013-02-02
          相关资源
          最近更新 更多