2011-09-06 128 views

回答

3

僅僅包括處於不同狀態(即聚焦,按下,檢查或正常)的單選按鈕的各個可繪圖。將其包含在selector.xml中以指定各個狀態的按鈕外觀,並將該xml包含在按鈕的android:background屬性中。這應該做到這一切...! :)

檢查此鏈接瞭解方法好:Change how a CheckBox looks (它被賦予了一個複選框,但類似的東西會爲按鈕,單選按鈕以及工作)。

編輯:

定義如下round_button.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_checked="true" android:state_focused="true" 
     android:drawable="@drawable/roundbutton_on_background_focus_yellow" /> 

    <item android:state_checked="false" android:state_focused="true" 
     android:drawable="@drawable/roundbutton_off_background_focus_yellow" /> 

    <item android:state_checked="false" 
     android:drawable="@drawable/roundbutton_off_background" /> 

    <item android:state_checked="true" 
     android:drawable="@drawable/roundbutton_on_background" /> 
</selector> 

然後,你需要的地方包括按鈕,只需添加以下內容:

<Button android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/round_button" 
    android:checked="true"/> 

[PS :不要忘記包含一個圓形按鈕的drawable,你必須自己搜索它們,或者從默認文件(.android)中獲取,它是在鏈接中給出]

+0

我明白了,但不知道如何開始。你會分享代碼片段嗎? – eros

+0

哦,我明白了,它會使用圖像。有沒有一種不使用圖像的方式? – eros

+0

我對此沒有想法。 – SamSPICA