设置 MaterialSpinner 的背景颜色
Set background color of MaterialSpinner
我在我的项目中将此 (https://github.com/ganfra/MaterialSpinner) 用于微调器。问题是我没有找到任何方法来改变微调器的背景。我尝试使用 android:background="#fff"
,然后尝试使用 android:theme="@style/myspinnertheme"
,它正在改变背景但仍然没有用。我不知道我可以尝试的另一种方法 :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 : "/>
这是我的项目截图:
你看底部的微调器,我想把背景颜色改成白色,怎么办?
这是因为 material spinner 在构造函数中设置了背景资源并更改了背景。因此,只需使用您的颜色重置背景资源即可。示例:
在 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>
并设置它
MaterialSpinner spinner = (MaterialSpinner) findViewById(R.id.spCategory);
spinner.setBackgroundResource(R.drawable.background);
您可以使用 custom:ms_baseColor="@color/green"
我在我的项目中将此 (https://github.com/ganfra/MaterialSpinner) 用于微调器。问题是我没有找到任何方法来改变微调器的背景。我尝试使用 android:background="#fff"
,然后尝试使用 android:theme="@style/myspinnertheme"
,它正在改变背景但仍然没有用。我不知道我可以尝试的另一种方法 :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 : "/>
这是我的项目截图:
你看底部的微调器,我想把背景颜色改成白色,怎么办?
这是因为 material spinner 在构造函数中设置了背景资源并更改了背景。因此,只需使用您的颜色重置背景资源即可。示例:
在 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>
并设置它
MaterialSpinner spinner = (MaterialSpinner) findViewById(R.id.spCategory);
spinner.setBackgroundResource(R.drawable.background);
您可以使用 custom:ms_baseColor="@color/green"