Android学习之设置Spinner下拉框的边框下划线颜色

Android学习之设置Spinner下拉框的边框下划线颜色

 

在style.xml中新增一个style,name 可以自定义,

 

其中colorAccent 的颜色属性代表点击Spinner时,边框下划线的颜色。

其中colorControlNormal的颜色属性代表正常情况,下划线和下拉箭头的颜色。

#e6e6e6 为颜色编码,可以任意修改编码来改变颜色

    <style name="ThemeSpinner">
        <!-- Color when pressed -->
        <item name="colorAccent">#e6e6e6</item>
        <!-- Default color for the dropdown arrow and line -->
        <item name="colorControlNormal">#e6e6e6</item>
    </style>

 

使用时,只需要在layout.xml中的Spinner控件中添加一句:android:theme="@style/ThemeSpinner"即可

 <Spinner
                        android:id="@+id/Spinner"
                        style="@style/Widget.AppCompat.Spinner.Underlined"
                        android:theme="@style/ThemeSpinner"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:entries="@array/DEFAULT" />

 


版权声明:本文为weixin_37879993原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。