2011-10-20 36 views
3

我一直在尋找一種簡單的方法來使我的整個應用程序中的所有按鈕都有圓角。主題中所有按鈕的圓角 - 如何重寫?

我還沒有成功,所以我認爲我會問=)

我的AndroidManifest.xml:

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/BlackTheme" android:alwaysRetainTaskState="true" android:name="MyApplication"> 

我styles.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="ButtonHeader" parent="@android:style/Widget.Button"> 
     <item name="android:textSize">18dip</item> 
     <item name="android:minWidth">70dip</item> 
     <item name="android:minHeight">20dip</item> 
     <item name="android:maxHeight">30dip</item> 
    </style> 

    <style name="JobViewHeader" parent="@android:style/TextAppearance.Small"> 
     <item name="android:textStyle">bold</item> 
     <item name="android:textColor">#FFFFFF</item> 
     <item name="android:layout_width">wrap_content</item> 
     <item name="android:layout_height">wrap_content</item> 
    </style> 

    <style name="BlackTheme" parent="@android:style/Theme.Black"> 
     <item name="android:button">@drawable/button_rounded</item> 
    </style> 

    <style name="DialogTheme" parent="@android:style/Theme.Dialog"> 
    </style> 
</resources> 

我的button_rounded.xml(可繪製):

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <corners android:radius="10dp" /> 
</shape> 
+0

您可以將它們全部更改爲「ImageButtons」,並使用PowerPoint中製作的圓角框的9修補繪圖。 :) –

+0

那麼,你遇到了什麼問題? –

+0

@LalitPoptani問題是這些按鈕沒有改變,它們根本不是圓形的。 – Ted

回答

0

據我瞭解,你想指定一些抽象的繪製(Shape Drawable你的情況)作爲按鈕的背景,這將在稍後與任何其他可繪製集作爲按鈕的背景相結合。不幸的是,這是不可能的。如果你想要一個帶有圓角的背景,你需要提供包含圓角的可繪製資源,不管它是什麼類型的可繪圖:形狀可繪製,九塊補丁等。

但是,你可以考慮子類化Button小部件並覆蓋其draw方法,您可以在其中按照您的需要操作按鈕的外觀。

+0

嗯,所以將背景設置爲具有圓角的可繪製對象將起作用?也許甚至像這樣:http://stackoverflow.com/a/3646629/175830? –

+0

是的,爲什麼不呢?使用Shape Drawable,例如: ' ' 並將其設置爲按鈕的背景。 –

+0

好的,只要我仍然可以按下按鈕的視覺和一切,這應該工作。 –