15

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?

0

1 Answer 1

18

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

style="?attr/loginPageContainerStyle" 

Figured I would share.

Sign up to request clarification or add additional context in comments.

1 Comment

Great example with android theme and styles. Just need to mention that on AndroidManifest on application tag need to add android:theme="@style/ThemeOne" or android:theme="@style/ThemeTwo" and that's all we need to know about themes

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.