【问题标题】:Theme not being applied未应用主题
【发布时间】:2017-12-31 10:29:07
【问题描述】:

我只是想改变一个活动的背景颜色,但没有任何改变。

这里是相关的 XML:

styles.xml

<resources>
<style name="STBTheme" parent="android:Theme.Light" >
    <item name="android:windowBackground">@color/blue</item>
</style>
</resources>

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.pedro.stb"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/STBTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" 
            android:theme="@style/STBTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

此外,我使用的是 Eclipse,通过更改活动 xml 中的主题,它不会在图形布局中发生变化。

有什么帮助吗?

编辑 让它工作。在重新加载布局之前必须清理项目。很烦人...

【问题讨论】:

  • 您是否在此活动中使用的 XML 布局中设置了任何颜色或主题?
  • @Dharmendra 我应该在活动的 XML 中的什么位置添加它?

标签: android android-layout android-theme


【解决方案1】:

我检查过你的代码没问题。

试试&lt;item name="android:Background"&gt;#ccff33&lt;/item&gt;

而不是你的&lt;item name="android:windowBackground"&gt;@color/blue&lt;/item&gt;.

你已经在应用程序和活动中写了android:theme="@style/STBTheme" &gt;

只写应用标签。

希望你现在能得到你的输出。

【讨论】:

  • 更改为 android:Background 会出错。将该标签仅放在应用程序中也不起作用。
【解决方案2】:
  1. Open the preview of your activity and Click on the circled button as shown

  2. Type the name of your custom theme and Click 'OK' as shown

  3. 在 Manifest 文件中将属性 android:theme=".YourTheme" 添加到所需的 Activity

您将更改当前活动的主题。

我不知道为什么 Android Studio 有时会表现得像喝醉了一样。我有两个具有相同目标的项目,最小 SDK 处于活动状态。其中一个正确实现了初始屏幕主题,另一个在我找到此解决方法之前不会显示。

【讨论】:

    猜你喜欢
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 1970-01-01
    相关资源
    最近更新 更多