Android:当我在列表中设置项目的背景时,为什么AlertDialog的背景会发生变化

时间:2015-07-06 22:35:35

标签: android alertdialog android-alertdialog android-appcompat

我的情况是这样的:我有v7.AlertDialog使用AlertDialog.Builder.setAdapter填充列表。当我的列表中的项目没有背景时,适配器上的标题和按钮具有白色背景。 enter image description here

但是,一旦我为列表中的项目添加了颜色(通过在适配器项目上设置背景属性),标题和按钮的背景将更改为窗口背景颜色,如下所示:enter image description here < / p>

我在hierarchyviewer中提取了视图,我注意到这发生了,因为AlertDialog上的标题部分和按钮没有背景。但是,当我的适配器中的项目没有背景时,为什么这会导致它们具有白色背景?难道它们仍然没有用窗口背景着色吗?

我能够通过设置窗口背景来解决这个问题,但它对我来说仍然只是好奇的行为。

我的适配器和视图的代码非常无趣。视图只是

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/some_shade_of_gray">

    <!-- A LinearLayout with some TextViews -->

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:src="@drawable/arrow_graphic"
        android:contentDescription="@null"/>

</RelativeLayout>

适配器中的getView方法看起来像。

public View getView(final int position, final View convertView, final ViewGroup parent) {
    View toReturn = convertView;
    if (toReturn == null) {
        toReturn = LayoutInflater.from(mContext).inflate(
                R.layout.address_view, parent, false);
        // Initialize a ViewHolder with a bunch of fields.
    }
    ViewHolder holder = (ViewHolder) toReturn.getTag();
    // set some text in TextViews

    return toReturn;
}

0 个答案:

没有答案