2012-05-11 22 views
0

我正在構建基於Android操作系統的最新版本的示例應用程序。根據給出的指令here我想給我的應用程序中只有一個按鈕全息:燈主題。我該怎麼做 ?我在res/values文件夾中創建了一個myStyles.xml,但我無法找到屬性來應用全光主題。全息燈主題沒有設置在按鈕上

這是我在myStyles.xml文件

<?xml version="1.0" encoding="UTF-8"?> 
<resources> 
<style name="mybutton" parent="android:Theme.Holo.Light"> 
    <item name="android:background">@android:color/holo_orange_light</item> 
    <item name="android:textColor">@android:color/holo_blue_dark</item> 
</style> 
</resources> 

這是我在我的活動。

<Button 
     android:id="@+id/button1" 
     style="@style/mybutton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="lol" /> 

我可以確認backgroundcolor和textcolor正在得到應用......(爲測試目的完成此操作)。 目前,如果我將android:theme =「@ android:style/Theme.Holo.Light」添加到AndroidManifest.xml,則holo light主題將應用於整個應用程序。不過,我希望這個主題僅適用於少數控件(在這種情況下是單個按鈕控件)。

回答

1

主題是應用於整個活動或應用程序的樣式,而不是單個視圖。

因此,你所要求的是不可能的。話雖如此,但無論如何你都會想要這樣做似乎很奇怪。我建議將整體主題應用於您的整個應用程序,然後僅在您確實需要時才自定義您的Button。這可能是用戶期望從您的應用程序。