Android changing colors with themes

喜欢而已 提交于 2019-12-17 16:41:49

问题


I am trying to provide user settable colors in my app. White text on black background and black text on white background. I have multiple layouts with many listviews, both standard and custom adapters. People have suggested using Themes, but I have had no luck changing the text colors across all layouts. Can anyone show me an actual Theme layout that can accomplish this? I can easily change the background colors using myscreen.setBackGroundColor(xx), but when I try to change the text with a theme, it also changes spinner text as well.


回答1:


Use

    <item name="android:spinnerStyle">@style/StandardSpinner</item>
    <item name="android:spinnerItemStyle">@style/StandardSpinnerItem</item>
    <item name="android:spinnerDropDownItemStyle">@style/StandardSpinnerDropDownItem</item>

in your theme, this will override the Text style.

Your style will look something like this:

<style name="StandardSpinner" parent="@android:style/Widget.Spinner">
    <item name="android:background">@drawable/spinner</item>
</style>

<style name="StandardSpinnerItem" parent="@android:style/Widget.TextView.SpinnerItem">
    <item name="android:textAppearance">@style/GameDisplayText</item>
    <item name="android:gravity">center_vertical|center_horizontal</item>
</style>

<style name="StandardSpinnerDropDownItem" parent="@android:style/Widget.DropDownItem.Spinner">
    <item name="android:textAppearance">@style/GameDisplayText</item>
</style>



回答2:


Just some extra information, in order to point you theme to your application you need to define it at the AndroidManifest.xml

ex.

<application android:icon="@drawable/icon" android:label="@string/app_name"    android:theme="@style/Theme">

you should reuse some of the defaults styles properties, so declare the android default theme as parent theme of yours

at values/styles.xml or wherever is your theme file

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme" parent="@android:style/Theme">
         <!-- Widget styles -->
         <item name="android:spinnerStyle">@android:style/Widget.Spinner</item>
         <item name="android:spinnerDropDownItemStyle">@style/Widget.DropDownItem.Spinner</item>
         <item name="android:spinnerItemStyle">@android:style/Widget.TextView.SpinnerItem</item>
    </style>


来源:https://stackoverflow.com/questions/3014152/android-changing-colors-with-themes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!