Android微调框颜色
问题描述:
我正在尝试使我的微调框的背景颜色变白。这是我想要对微调控制器做出的唯一改变,但是我看到的每个解决方案都需要制作自定义微调控制器,更改样式,或者其他一些漫长而过度复杂的过程,以更改颜色。有没有办法轻松改变颜色。我喜欢创建drawable并将其设置为背景的方法。我在下面找到的解决方案适用于api> = 23,但我需要的是最小为19的东西。有没有简单的方法,还是必须创建自定义微调器才能更改颜色?这正是我试图让它看起来像。Android微调框颜色
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/splashColor" />
</item>
<item android:gravity="center_vertical|right" android:right="8dp">
<layer-list>
<item android:width="12dp" android:height="12dp" android:gravity="center" android:bottom="11dp">
<rotate android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#000000" />
<stroke android:color="#aaaaaa" android:width="1dp"/>
</shape>
</rotate>
</item>
<item android:width="30dp" android:height="10dp" android:bottom="21dp" android:gravity="center">
<shape android:shape="rectangle">
<solid android:color="@color/splashColor"/>
</shape>
</item>
</layer-list>
</item>
</layer-list>
使用不设置宽度/高度简化版本(需要> = 23)看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="@android:color/white" />
</shape>
</item>
<item>
<bitmap
android:gravity="end"
android:src="@drawable/arrow_dropdown" />
</item>
</layer-list>
但它使高度过大,使得整个屏幕似乎关闭。我不知道如何改变高度23 23
答
最后我用第二种方法,只是手动设置微调器的高度。这是微调代码最终的样子。
<Spinner
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="@drawable/custom_spinner"
android:id="@+id/type" />
custom_spinner
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="@android:color/white" />
</shape>
</item>
<item>
<bitmap
android:gravity="end"
android:src="@drawable/arrow_dropdown" />
</item>
</layer-list>
答
您可以为它设置一个主题属性。
使用自定义命名空间并进行设置。
Ex。
<ProgressBar
....
app:theme="@style/custom_style"
/>
其中custom_style是你的风格目录定义为:
<style name="custom_style" parent="Theme.AppCompat">
<item name="colorControlNormal"><!--this color is not of importance --></item>
<item name="colorControlActivated">#FFFFFF</item>
</style>
添加白色的进度颜色。适用于评分栏。假设也应该为进度条工作。