如何更改微调器的背景颜色? [英] how can i change spinner background color?
本文介绍了如何更改微调器的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改微调器的背景颜色?
How can i change spinner background color ?
这是样式中的黑色.
如何更改微调框弹出的样式颜色?
How can i change style color for spinner pop up?
我想将背景颜色更改为黑色,而不是黑色.
I want to change background color white in place of black How can i change ?
旋转者
<Spinner
android:id="@+id/spinner"
android:layout_width="100dp"
android:layout_marginTop="1dp"
android:layout_height="wrap_content"
android:background="@drawable/spinner_bg"
android:layout_marginLeft="1dp"/>
spinnerbg.xml
spinnerbg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/InputBg1" />
</item>
<item android:gravity="center_vertical|right" android:right="8dp">
<layer-list>
<item android:width="12dp" android:height="12dp" android:background="#fff" android:gravity="center" android:bottom="10dp">
<rotate
android:fromDegrees="45"
android:toDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
<stroke android:color="#ffffff" android:width="1dp"/>
</shape>
</rotate>
</item>
<item android:width="20dp" android:height="10dp" android:bottom="21dp" android:background="#fff" android:gravity="center">
<shape android:shape="rectangle">
<solid android:color="@color/InputBg1"/>
</shape>
</item>
</layer-list>
</item>
</layer-list>
推荐答案
事物耦合与自定义微调器有关,如下所示:-
Couple of things need to do with customization spinner as per below :-
spinner_bg.xml
spinner_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/InputBg1" />
</item>
<item android:gravity="center_vertical|right" android:right="8dp">
<layer-list>
<item android:width="12dp" android:height="12dp" android:gravity="center" android:bottom="10dp">
<rotate
android:fromDegrees="45"
android:toDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
<stroke android:color="#ffffff" android:width="1dp"/>
</shape>
</rotate>
</item>
<item android:width="20dp" android:height="10dp" android:bottom="21dp" android:gravity="center">
<shape android:shape="rectangle">
<solid android:color="@color/InputBg1"/>
</shape>
</item>
</layer-list>
</item>
</layer-list>
spinner_item.xml
spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="@style/spinnerItemStyle"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:ellipsize="marquee"
android:textAlignment="inherit"/>
spinner_dropdown_item.xml
spinner_dropdown_item.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="@style/spinnerItemStyle"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:ellipsize="marquee"/>
旋转器
<Spinner
android:id="@+id/spinner"
android:layout_width="100dp"
android:popupBackground="#ffffff"
android:layout_marginBottom="1dp"
android:layout_height="wrap_content"
android:textColor="#ffff"
style="@style/spinnerItemStyle"
android:background="@drawable/spinner_bg"
android:layout_marginLeft="1dp" />
style.xml
style.xml
<style name="spinnerItemStyle" parent="@android:style/Widget.Holo.DropDownItem.Spinner">
<item name="android:textColor">#000000</item>
</style>
为微调框创建适配器
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
这篇关于如何更改微调器的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文