Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android,如何为TextView小部件设置字体颜色主题?_Android_Android Theme - Fatal编程技术网

Android,如何为TextView小部件设置字体颜色主题?

Android,如何为TextView小部件设置字体颜色主题?,android,android-theme,Android,Android Theme,我刚刚在我的主题中使用了一个黑色背景图像 <style name="AppBaseTheme" parent="Theme.Sherlock.Light"> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <item name="android:windowBackground">@drawable/backg

我刚刚在我的主题中使用了一个黑色背景图像

<style name="AppBaseTheme" parent="Theme.Sherlock.Light">
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowBackground">@drawable/background</item>
</style>

@可绘制/背景
现在我想把我的文本视图的颜色改成白色,这样在黑暗的背景下就可以看到它们

我认为为TextView设置android:textColor会达到这样的效果

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowBackground">@drawable/background</item>
    <item name="android:textViewStyle">@style/Ff1TextViewStyle</item>
</style>


<style name="Ff1SpinnerViewStyle" parent="android:Widget.TextView">
    <item name="android:textColor">@color/sysWhite</item>
    <item name="android:textStyle">bold</item>
</style>

@可绘制/背景
@样式/Ff1TextViewStyle
@颜色/系统白
大胆的
但令我沮丧的是,这完全塞满了各种各样的东西,比如微调器文本和微调器下拉文本,ActionBar下拉菜单通过将白色背景上的文本更改为白色,所有这些都是我以前非常满意的,而且我相信我还没有使用或还没有发现的其他控件最终可能会变成白色文本

我发现很难相信android主题如此混乱,以至于我无法自信地设置TextView widgets的文本颜色而不影响小部件,我只能假设,我是TextView小部件的孩子,所以我认为这应该归咎于我的知识不足,我希望并寻求对这一共同需求的启示


非常感谢您的帮助。

您可以创建一个样式,并仅将其应用于
文本视图中的特定元素,例如布局xml文件中的:

<TextView
    style="@style/Ff1SpinnerViewStyle"
    android:id="@+id/myView" />

如果将标准主题应用于活动,则只有在布局文件中覆盖样式的元素的外观才会发生更改


您不需要使用任何
TextView
特定属性覆盖
AppBaseTheme

我不确定您是否可以只为
TextView
设置样式,因为
Actionbar
微调器
和其他
视图也包含
TextView
,所以当你发现的时候,它也会影响到他们。在我看来,您应该创建一个样式并将其设置为您的
TextView
。类似于此:

 <style name="MyTextView" parent="@android:style/TextAppearance.Small">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:textSize">12sp</item>
</style>
或者,您可以做的第二件事是创建自定义
TextView

public class MyTextView extends TextView {

     public MyTextView(Context context){
         super(context);
         this.setTextColor(android.R.color.white);
     }
}
并在xml文件中使用MyTextView:

<com.my.package.name.MyTextView
   android:id="@+id/my_textview" />

编辑:

之所以设置
android:textViewStyle
会影响所有其他视图,是因为如果仔细查看android源代码,您会发现其他视图中使用的每个textview样式都是
android.Widget.textview
的子视图。因此,在我看来,在这种情况下,您可以做的最好的事情是创建一个单一样式,并将其设置为xml格式的
TextView


希望这些信息能有所帮助

是的,谢谢,但是我有50多个文本视图,而且在增长,所以我想使用themeCustom文本视图小部件,这似乎是目前最好的方式。谢谢。感谢您的解决方案,此解决方案将在单个
TextView
小部件中为我节省大量代码重复
<com.my.package.name.MyTextView
   android:id="@+id/my_textview" />