【问题标题】:Setting text color to theme in Android is not working在 Android 中将文本颜色设置为主题不起作用
【发布时间】:2016-05-28 08:12:41
【问题描述】:

我正在使用 Android Studio 开发一个 Android 应用。坦率地说,我不擅长 Android 开发。我在为我的应用程序设置主题时遇到问题。我在样式资源文件中为整个应用程序设置文本颜色作为主题。但它不起作用。

这是我的颜色资源文件:

如您所见,我将两种文本颜色都设置为红色。

这是我在样式资源文件中的主题:

我在清单文件中为应用程序设置主题,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.deltatripagent.deltatripagent" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

但是当我运行文本颜色并没有改变。你可以在下面看到。

如何为整个应用程序设置文本颜色?

【问题讨论】:

    标签: android android-theme android-styles


    【解决方案1】:

    您的活动主题正确设置为AppTheme.NoActionBar。但是,该主题在您的 styles.xml 中没有父主题,这意味着 TextView 颜色不会从默认值更改。您可以通过从 AppTheme 继承来解决此问题,如下所示:

    <style name="AppTheme.NoActionBar" parent="AppTheme">
    

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 2019-05-21
      • 1970-01-01
      • 2021-10-09
      • 2019-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多