【发布时间】:2017-05-13 03:17:10
【问题描述】:
我需要将Spinner 中的Spinner 所选项目颜色设置为白色,该Toolbar 位于Toolbar 上。应用中所有其他 Spinners 的颜色应保持不变。
我试过了。
styles.xml
<style name="SpinnerOnPrimaryStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:spinnerItemStyle">@style/mySpinnerItemStyle</item>
</style>
<style name="mySpinnerItemStyle" parent="android:Widget.TextView.SpinnerItem">
<item name="android:textColor">@color/text_on_primary</item>
</style>
工具栏
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tab_background"
android:gravity="center_vertical"
app:theme="@style/ToolBarStyle">
<Spinner
android:id="@+id/categorySpinner"
app:theme="@style/SpinnerOnPrimaryStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
</android.support.v7.widget.Toolbar>
但是,Spinner 的颜色没有改变。
如果我将基本主题的android:spinnerItemStyle 设置为mySpinnerItemStyle,Spinner 颜色就会改变。但这会改变应用程序中所有Spinners 的颜色,这是我不希望发生的。
(以下应用主题更改微调器颜色,但会更改所有微调器的颜色)
<!-- Application theme. -->
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:spinnerItemStyle">@style/mySpinnerItemStyle</item>
</style>
如何仅更改Toolbar 中Spinner 的颜色?如果我可以单独在主题中执行此操作,而不以编程方式执行此操作,那就更好了。
【问题讨论】:
-
代替
app:theme做android:theme。 -
@azizbekian 尝试过(也尝试过
style)但没有运气
标签: android android-view android-spinner android-theme android-styles