Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference a style in a custom theme

I have a login screen that is branded differently for different builds of my application. I need the background image to be different in the layout file for this screen, so I want to point to a different style for the top level container. I'm a bit at a loss at how to do this.

I have declared a styleable something like:

<resources>

    <declare-styleable name="ThemeBase">
       <attr name="loginPageContainerStyle" format="reference" />
    </declare-styleable>

</resources>

I have several different themes for the application, as such:

<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>

And I have defined the following styles:

<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>

And finally a login.xml file something like:

<?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>

Am I doing anything wrong? Can this be done this way?

like image 798
Christopher Perry Avatar asked Jun 15 '12 17:06

Christopher Perry


1 Answers

Ok I figured it out, the style reference should be:

style="?attr/loginPageContainerStyle"

Figured I would share.

like image 179
Christopher Perry Avatar answered Nov 06 '22 13:11

Christopher Perry