我有一个登录屏幕,它的商标针对我的应用程序的不同版本而有所不同。我需要该屏幕的布局文件中的背景图像不同,因此我想为顶层容器指向不同的样式。我对如何做到这一点有点茫然。
我已经声明了类似的样式:
<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>
我做错什么了吗?可以这样吗?
最佳答案
好的,我弄清楚了,样式引用应该是:
style="?attr/loginPageContainerStyle"
想通了,我会分享。