2012-06-15 35 views
13

我有一個登錄屏幕,對於我的應用程序的不同構建以不同的方式進行品牌標記。我需要背景圖像在這個屏幕的佈局文件中有所不同,所以我想指向頂級容器的不同樣式。我在如何做到這一點上有點不知所措。如何引用自定義主題中的樣式

我已經聲明瞭一個設置樣式類似:

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

我做錯了什麼?這可以這樣做嗎?

回答

14

好吧,我想通了,風格應參考:

style="?attr/loginPageContainerStyle" 

想我會分享。

+1

Android主題和樣式的很好的例子。只需要提及在AndroidManifest上的應用標籤需要添加android:theme =「@ style/ThemeOne」或android:theme =「@ style/ThemeTwo」,這就是我們需要了解的主題 – Ragaisis

+0

非常感謝。正是我在找什麼。 – dentex

相關問題