Android 在Dialog中使用Spinner时,下三角图标覆盖在按钮上的解决方法

1.如果是系统开发者,则直接修改frameworks/base/core/res/res/drawable/spinner_background_material.xml为如下内容即可:

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
            android:paddingMode="stack"
            android:paddingStart="0dp"
            android:paddingEnd="24dp"
            android:paddingLeft="0dp"
            android:paddingRight="0dp">
    <item
        android:gravity="end|center_vertical"
        android:width="24dp"
        android:height="24dp">
        <!--android:drawable="@drawable/zzz_control_background_24dp_material"-->
        <ripple
            android:color="@color/control_highlight_material"
            android:radius="12dp">
            <item
                android:id="@android:id/mask"
                android:width="24dp"
                android:height="24dp">
                <shape android:shape="oval">
                    <solid android:color="@android:color/white" />
                    <size
                        android:width="24dp"
                        android:height="24dp" />
                </shape>
            </item>
            <item
                android:width="24dp"
                android:height="24dp"
                android:drawable="@drawable/ic_spinner_caret"
                android:gravity="end|center_vertical"/>
        </ripple>
    </item>
    
    <!--<item-->
        <!--android:drawable="@drawable/ic_spinner_caret"-->
        <!--android:gravity="end|center_vertical"-->
        <!--android:width="24dp"-->
        <!--android:height="24dp" />-->
</layer-list>


2、如果是应用开发者,则可以重新给Spinner设置background,方法如下:

1:在res/drawable 下新建 spinner_background.xml 文件,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    android:opacity="transparent"
    android:paddingEnd="24dp"
    android:paddingLeft="0dp"
    android:paddingMode="stack"
    android:paddingRight="0dp"
    android:paddingStart="0dp">
    <item
        android:width="24dp"
        android:height="24dp"
        android:gravity="end|center_vertical">
        <ripple
            android:color="@color/control_highlight_material"
            android:radius="12dp">
            <item
                android:id="@android:id/mask"
                android:width="24dp"
                android:height="24dp">
                <shape android:shape="oval">
                    <solid android:color="@android:color/white" />
                    <size
                        android:width="24dp"
                        android:height="24dp" />
                </shape>
            </item>
            <item
                android:width="24dp"
                android:height="24dp"
                android:gravity="end|center_vertical">
                <aapt:attr name="android:drawable">
                    <vector xmlns:android="http://schemas.android.com/apk/res/android"
                        android:width="24dp"
                        android:height="24dp"
                        android:tint="?android:attr/colorControlNormal"
                        android:viewportHeight="24.0"
                        android:viewportWidth="24.0">
                        <path
                            android:fillColor="#FF333333"
                            android:pathData="M7,10l5,5,5-5z" />
                    </vector>
                </aapt:attr>
            </item>
        </ripple>
    </item>
</layer-list>


如果 aapt:attr 有问题的话,可以将这部分拆分成一个单独的 ic_spinner_arrow.xml (置于res/drawable中)文件,然后设置item的属性 android:drawable="@drawable/ic_spinner_arrow" ,ic_spinner_arrow.xml 内容如下:

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0"
        android:tint="?android:attr/colorControlNormal">
    <path
        android:pathData="M7,10l5,5,5-5z"
        android:fillColor="#FF333333"/>
</vector>
然后设置

2:在res/color 目录下新建文件 control_highlight_material.xml 文件,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true"
          android:state_enabled="true"
          android:alpha="@dimen/highlight_alpha_material_colored"
          android:color="?android:attr/colorControlActivated" />
    <item android:color="?android:attr/colorControlHighlight" />
</selector>


3:设置Spinner 的background 为 spinner_background

该bug现象如下:




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

songtao542

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值