Chr*_*rry 15 android themes android-styles
我有一个登录屏幕,针对我的应用程序的不同版本进行了不同的标记.我需要在此屏幕的布局文件中背景图像不同,所以我想指向顶级容器的不同样式.我对如何做到这一点有点不知所措.
我宣布了一个像样的东西:
<resources>
<declare-styleable name="ThemeBase">
<attr name="loginPageContainerStyle" format="reference" />
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
我有几个不同的主题的应用程序,因此:
<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>
Run Code Online (Sandbox Code Playgroud)
我定义了以下样式:
<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>
Run Code Online (Sandbox Code Playgroud)
最后一个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>
Run Code Online (Sandbox Code Playgroud)
我做错了吗?这可以这样做吗?
Chr*_*rry 15
好吧我明白了,样式参考应该是:
style="?attr/loginPageContainerStyle"
Run Code Online (Sandbox Code Playgroud)
想我会分享.
| 归档时间: |
|
| 查看次数: |
2700 次 |
| 最近记录: |