代码之家  ›  专栏  ›  技术社区  ›  EboMike

如何更改主题中的textColorPrimary?

  •  8
  • EboMike  · 技术社区  · 14 年前

    我正在使用setTheme更改onCreate中活动的主题(我甚至在调用super.onCreate()之前就这样做了,因为这样应该更可靠)。

    我试图覆盖我的主题中的主要文本颜色,但这似乎不起作用。

    以下是主题的关键部分:

    <style name="Theme.MyApp.White">
       <item name="android:background">@android:color/white</item>
       <item name="android:textColor">#000000</item>
    </style>
    

    背景显示为白色,纯文本视图显示为黑色。。。但是使用textAppearanceLarge的textView是白色的,因此是不可见的(白色对白色)。

       <item name="android:ColorPrimary">#000000</item>
       <item name="android:textColorPrimary">#000000</item>
       <item name="android:attr/textColorPrimary">#000000</item>
    

    但这些都没用。魔术是什么?

    3 回复  |  直到 14 年前
        1
  •  7
  •   zsniperx    14 年前

    作为解决方法,而不是使用 textAppearanceLarge 样式在styles.xml中,除了可以将颜色更改为白色之外,它模拟android默认样式。

    xml布局:

    <!-- example textview -->
    <TextView style="@style/large" android:text="text goes here"></TextView>
    

    然后在styles.xml中

    <style name="large">
        <item name="android:textColor">@android:color/white</item>
        <!-- other necessary items here like font etc.-->
    </style>
    
        2
  •  4
  •   Akos Cz    14 年前

    “样式”和“主题”之间的唯一区别是样式应用的范围。应用于活动的样式称为主题。

    以下是一篇关于这个话题的好文章: http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/

        3
  •  1
  •   EboMike    14 年前

    android:background 在我的主题中,所有的东西都是一团糟,所有的文本都是白色的,尽管我覆盖了所有的颜色(包括textColorPrimary)。省略 android:background