2011-12-13 51 views
1

我想重載一個android Button的外觀,除了我只想重載一個屬性,即android:background。我知道我可以寫的東西,如:想要過載按鈕樣式

<style name="App_TextButtonStyle" parent="???"> 
    <item name="android:background">@drawable/filled_roundededges_nostroke</item> 
</style> 

parent="???"指定哪一種風格我繼承。我的問題是我應該繼承哪種風格,我從android的默認樣式獲取所有的按鈕,並定義一個新的背景。

回答

1

這主要是爲未來的訪客,我找到了一個解決問題的辦法:

<style name="App_TextButtonStyle" parent="@android:style/Widget.Button"> 
    <item name="android:background">@drawable/filled_roundededges_nostroke</item> 
</style> 

@android:style/Widget.Button引用當前選定的主題按鈕的默認樣式。您也可以使用全息小部件按鈕樣式@android:style/Widget.Holo.Button(自api 11起可用)。

您可能需要查看<android-sdk-install-folder>/platforms/android-XX/data/res/values中的文件styles.xmlthemes.xml,以查看android在給定平臺版本中使用的所有樣式。

+0

你是如何讓你的主題使用這種風格的?添加這個不適用於我的: @ style/App_TextButtonStyle。 – Eliot

1

我已經使用樣式按鈕不指定「父」屬性

<style name="BigButtonStyle"> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:layout_gravity">center_horizontal</item> 
    <item name="android:background">@drawable/backbutton</item> 
    <item name="android:textColor">#FFFFFF</item> 
    <item name="android:textSize">8pt</item> 
    <item name="android:textStyle">bold</item> 
    <item name="android:layout_margin">10pt</item> 
</style> 

我認爲這可能是足以讓你定義你的風格沒有「父」。

+0

我的問題是如何決定目前使用的主題顏色?我的意思是,在一個簡單的主題中,一個白色的按鈕可能看起來不錯,但是在像4.0這樣的卡片主題中,一個白色的按鈕看起來很奇怪。我想只能重載屬性,而剩下的則取決於當前的主題。 –

+0

這是最接近的,即使遠非理想解決方案,我發現問題。 –