Android TextView textColor无法更改(AppCompat)

时间:2017-05-01 20:45:00

标签: android android-layout

你好伙计堆叠花,如果你的帮助,我需要。

我在移动应用程序中使用Theme.AppCompat.Light.DarkActionBar.NoActionBar主题。

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
        </style>

        <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>

我的片段中似乎忽略了android:textColor属性。文本颜色默认为grey颜色。它在预览窗口中工作正常。

我也尝试过使用textview元素的主题而没有任何运气。

这是我使用的风格主题。

<style name="textView">           
            <item name="android:textColor">@color/colorIcons</item>          
        </style>

  <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Client Name"
            android:paddingLeft="5dp"
            android:theme="@style/textView"
            />

更令人惊讶的是,当我设置android:background"时,背景显示为预期。但它是我想要工作的文字颜色。

谢谢。

1 个答案:

答案 0 :(得分:0)

确保主题应用于AndroidManifest.xml中的应用程序

如果单独这样做不行,请尝试将其插入片段的onCreateView()。

final Context context = new ContextThemeWrapper(getActivity,R.style.textView)
final LayoutInflater inflater1 = inflater.cloneInContext(context);

使用此inflater1来膨胀片段的视图。

相关问题