在 ActionBar 上设置 Spinner 的样式
Styling a Spinner on the ActionBar
我正忙于设计我的应用程序的主题(blue/black 带有橙色边缘)。我成功管理了操作栏,但操作栏中的 spinner/dropdown 出现问题。任何人都可以建议我必须做些什么才能使微调器内的文本颜色也变成橙色。不是实际的微调器项目,只是显示在顶部的项目,即所选项目。
目前看起来是这样的:
我为微调器使用的样式如下所示:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
</style>
<!-- SQUASHBOT THEME -->
<style name="SquashBotTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/SquashBotTheme.ActionBarTheme</item>
<item name="android:actionDropDownStyle">@style/SquashBotTheme.DropDownNavigation</item>
</style>
<!-- ACTIONBAR THEME -->
<style name="SquashBotTheme.ActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/actionbar_theme</item>
<item name="android:titleTextStyle">@style/SquashBotTheme.TitleText</item>
</style>
<!-- TITLE TEXT -->
<style name="SquashBotTheme.TitleText" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:textColor">@color/OrangeRed</item>
</style>
<!-- DROPDOWN ITEM -->
<style name="SquashBotTheme.DropDownNavigation" parent="@android:style/Widget.Holo.Spinner">
<item name = "android:textAppearance">@color/OrangeRed</item>
<item name = "android:textColor">@color/OrangeRed</item>
<item name = "android:popupBackground">@color/OrangeRed</item>
</style>
</resources>
如您所见,我已经尝试使用 textAppearance
和 textColor
。任何建议将不胜感激。
你可以试试这个:
spinner_item.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/YourStyleIsHere"
android:background="@color/white"
android:layout_width="match_parent"
android:singleLine="true"
android:drawableRight="@drawable/ic_action_dropdawn2"
android:ellipsize="end" />
dropdown_item.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/YourAnotherStyle"
android:layout_width="match_parent"
android:background="@drawable/phone_ripple"
android:padding="20dp"
android:ellipsize="end" />
适配器
adapter = new YourAdapter(context, R.layout.spinner_item, models);
adapter.setDropDownViewResource(R.layout.dropdown_item);
样式有父级@android:style/TextAppearance"
我正忙于设计我的应用程序的主题(blue/black 带有橙色边缘)。我成功管理了操作栏,但操作栏中的 spinner/dropdown 出现问题。任何人都可以建议我必须做些什么才能使微调器内的文本颜色也变成橙色。不是实际的微调器项目,只是显示在顶部的项目,即所选项目。
目前看起来是这样的:
我为微调器使用的样式如下所示:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
</style>
<!-- SQUASHBOT THEME -->
<style name="SquashBotTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/SquashBotTheme.ActionBarTheme</item>
<item name="android:actionDropDownStyle">@style/SquashBotTheme.DropDownNavigation</item>
</style>
<!-- ACTIONBAR THEME -->
<style name="SquashBotTheme.ActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/actionbar_theme</item>
<item name="android:titleTextStyle">@style/SquashBotTheme.TitleText</item>
</style>
<!-- TITLE TEXT -->
<style name="SquashBotTheme.TitleText" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:textColor">@color/OrangeRed</item>
</style>
<!-- DROPDOWN ITEM -->
<style name="SquashBotTheme.DropDownNavigation" parent="@android:style/Widget.Holo.Spinner">
<item name = "android:textAppearance">@color/OrangeRed</item>
<item name = "android:textColor">@color/OrangeRed</item>
<item name = "android:popupBackground">@color/OrangeRed</item>
</style>
</resources>
如您所见,我已经尝试使用 textAppearance
和 textColor
。任何建议将不胜感激。
你可以试试这个:
spinner_item.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/YourStyleIsHere"
android:background="@color/white"
android:layout_width="match_parent"
android:singleLine="true"
android:drawableRight="@drawable/ic_action_dropdawn2"
android:ellipsize="end" />
dropdown_item.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/YourAnotherStyle"
android:layout_width="match_parent"
android:background="@drawable/phone_ripple"
android:padding="20dp"
android:ellipsize="end" />
适配器
adapter = new YourAdapter(context, R.layout.spinner_item, models);
adapter.setDropDownViewResource(R.layout.dropdown_item);
样式有父级@android:style/TextAppearance"