主题未被应用

问题描述 投票:0回答:2

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

这是相关的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,并且通过更改activity的xml中的主题,它在图形布局中不会改变。

有帮助吗?

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

android android-layout android-theme
2个回答
1
投票

我检查你的代码是好的。

试试<item name="android:Background">#ccff33</item>

而不是你的<item name="android:windowBackground">@color/blue</item>.

你还在应用程序和活动中写了android:theme="@style/STBTheme" >

只需写入应用程序标签。

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


1
投票
  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活动。其中一个正确实现了启动画面主题,另一个只是在我找到这个解决方法之前不会显示。

© www.soinside.com 2019 - 2024. All rights reserved.