【发布时间】:2012-06-15 17:32:56
【问题描述】:
我有一个登录屏幕,该屏幕针对我的应用程序的不同构建进行了不同的标记。我需要此屏幕的布局文件中的背景图像不同,因此我想为顶级容器指向不同的样式。我对如何做到这一点有点不知所措。
我已经声明了一个类似的样式:
<resources>
<declare-styleable name="ThemeBase">
<attr name="loginPageContainerStyle" format="reference" />
</declare-styleable>
</resources>
我有几个不同的应用主题,例如:
<resources>
<style name="ThemeBase" parent="android:style/Theme.Light" />
<style name="ThemeOne" parent="ThemeBase">
<item name="loginPageContainerStyle">@style/loginPageContainerThemeOne</item>
</style>
<style name="ThemeTwo" parent="ThemeBase">
<item name="loginPageContainerStyle">@style/loginPageContainerThemeTwo</item>
</style>
</resources>
我已经定义了以下样式:
<resources>
<style name="loginPageContainerThemeOne">
<item name="android:background">@drawable/background_theme_one</item>
</style>
<style name="loginPageContainerThemeTwo">
<item name="android:background">@drawable/background_theme_two</item>
</style>
</resources>
最后是一个 login.xml 文件,类似于:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loginRoot"
style= [ ? WHAT GOES HERE ? ]
android:gravity="center_horizontal"
android:orientation="horizontal">
[ LAYOUT STUFF ... ]
</LinearLayout>
我做错了吗?可以这样吗?
【问题讨论】:
标签: android themes android-styles