2014-12-03 67 views
-2

我想簡單地在沒有廣場的情況下打勾。也只有像ImageView會好。任何人都知道Android中資源的名稱?沒有廣場的複選框android

+0

份額截圖所需輸出 – 2014-12-03 11:00:50

+0

的,我想只有圖像,像這樣:http://icons.iconarchive.com/icons/visualpharm/must-have/24/Check-icon.png 但是,如果不使用我定義的圖像,我想使用系統圖像(如果可能的話)。 – Filnik 2014-12-03 11:04:24

+0

它不會*永遠不可能* – 2014-12-03 11:08:00

回答

3

只需將選擇器設置爲可繪製左側至Checkbox即可。

這樣做。

<CheckBox 
    android:id="@+id/checkbox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:button="@null" 
    android:drawableLeft="@drawable/checkImageSelector" /> 

android:button="@null"將刪除正方形的默認圖像蜱和drawableLeft將會把你的形象來代替這一點。

checkImageSelector.xml會是這樣的。

<selector xmlns:android="http://schemas.android.com/apk/res/android">  
    <item android:drawable="@drawable/check" android:state_selected="true"/>  
    <item android:drawable="@drawable/unchecked"/> 
</selector> 
+0

uhmmmm ..你能給我一個結果XML代碼的例子嗎? – Filnik 2014-12-03 10:59:29

+0

嗯,但我只想擁有支票的「系統圖像」,現在由我定義的 – Filnik 2014-12-03 11:02:17

+1

我認爲不能完成,您將需要自己的圖像,因爲不同的設備有不同的圖標複選框。 – Nitesh 2014-12-03 11:04:40

0

需要兩個圖像進行檢查選中狀態

創建具有相同的資源selector

checkbox_selector.xml:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/checked_image" android:state_checked="true"/> 
    <item android:drawable="@drawable/unchecked_image"/> 

</selector> 

然後設置此選擇的按鈕:

<CheckBox 
    android:id="@+id/checkbox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:button="@drawable/checkbox_selector" /> 
+0

所以不能使用Android使用的圖片來完成? (我已經知道如何用自定義圖像做到這一點..我想避免,如果可能:))。 – Filnik 2014-12-03 11:08:24

+1

**否**你不能做你在說什麼 – 2014-12-03 11:08:55

+0

好的,謝謝:) – Filnik 2014-12-03 11:10:22