[英]Set background color of MaterialSpinner
I am using this ( https://github.com/ganfra/MaterialSpinner ) for my spinner in my project. 我在我的项目中为我的微调器使用了这个( https://github.com/ganfra/MaterialSpinner )。 The problem is i did't find any way to change the spinner's background.
问题是我没有找到任何方法来更改微调器的背景。 I've try to use
android:background="#fff"
, then try to use android:theme="@style/myspinnertheme"
which is changeing the background but still did't work. 我尝试使用
android:background="#fff"
,然后尝试使用android:theme="@style/myspinnertheme"
背景,但仍然无法正常工作。 I don't know another way i can try :D 我不知道我可以尝试的另一种方法:D
<fr.ganfra.materialspinner.MaterialSpinner
android:id="@+id/spCategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="#fff"
app:ms_baseColor="@color/colorAccent"
app:ms_floatingLabelText="Kategori"
app:ms_enableErrorLabel="true"
app:ms_hint="Pilih Kategori : "/>
This is my project screen shoot : 这是我的项目屏幕截图:
Look at the spinner at bottom, i want to change the background color to white, what shall i do? 看一下底部的微调器,我要将背景色更改为白色,该怎么办?
It happens because material spinner set background resources in constructor and changes your background. 发生这种情况是因为材料微调器在构造函数中设置了背景资源并更改了背景。 So just reset background resources with your color.
因此,只需使用您的颜色重置背景资源即可。 Example:
例:
Create background.xml in drawable( colors for default, pressed and selected spinner's state) 在drawable中创建background.xml(颜色为默认值,按下状态和选定的微调器状态)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@android:color/darker_gray"/>
</shape>
</item>
<item android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="@android:color/darker_gray"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/black"/>
</shape>
</item>
And set it 并设置它
MaterialSpinner spinner = (MaterialSpinner) findViewById(R.id.spCategory);
spinner.setBackgroundResource(R.drawable.background);
您可以使用custom:ms_baseColor =“ @ color / green”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.