當前位置:首頁 » 安卓系統 » checkbox的樣式android

checkbox的樣式android

發布時間: 2022-08-18 19:53:44

『壹』 該如何改變checkbox被選中時那個勾勾的顏色 Android

首先你要准備兩張圖,一張是未勾選的checkbox樣式圖,一張是勾選的樣式圖。

然後在drawable文件夾中添加drawable文件checkbox_style.xml。
如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 勾選的樣式圖放到res目錄下的drawable中,然後在這里使用 -->

<item android:drawable="@drawable/checkbox_pressed" android:state_checked="true"/>
<!-- 未勾選的樣式圖放到res目錄下的drawable中,然後在這里使用 -->
<item android:drawable="@drawable/checkbox_normal" android:state_checked="false"/>
<item android:drawable="@drawable/checkbox_normal"/>

</selector>
再來是在values文件夾下的styles.xml文件中添加CustomCheckboxTheme樣式。
<style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_style</item>
</style>
最後在布局文件中使用CustomCheckboxTheme樣式。
<CheckBox
android:id="@+id/select_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/CustomCheckboxTheme" />

『貳』 android 如何改變checkbox樣式

1、首先res/drawable中定義編寫如下樣式:
<?xml version="1.0" encoding="utf-8"?>

<item android:drawable="@drawable/check_true" android:state_checked="true"></item>
<item android:drawable="@drawable/check_true" android:state_selected="true"></item>
<item android:drawable="@drawable/check_true" android:state_pressed="true"></item>
<item android:drawable="@drawable/check_false"></item>
</selector>

2、在layout中添加checkbox控制項

<CheckBox
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_check"
android:button="@null"
android:checked="true"/>
其中drwable/btn_check為1中頂一個文件名稱,另外必須將android:button設置為@null。
@drawable/check_true和@drawable/check_false為checkbox不同狀態的圖片,可自行設計。

『叄』 android中的checkBox如何實現單選

Android中checkbox默認為復選框,也就是多選,實現單選的話,可以讓checkbox添加監聽,當已經有一個點擊了,點擊另外一個的時候,修改默認的狀態,實現單選,示例如下:

java">publicstaticinttemp=-1;
checkBox=(CheckBox)parentView.findViewById(R.id.cbox_isselect);
//做個標記
checkBox.setId(groupPosition);
//checkbox監聽
checkBox.setOnCheckedChangeListener(newOnCheckedChangeListener(){
@Override
publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){
if(isChecked)
{
//這段代碼來實現單選功能
if(temp!=-1)
{
CheckBoxtempButton=(CheckBox)MyRingBoxActivity.this.findViewById(temp);
if(tempButton!=null)
{
tempButton.setChecked(false);
}
}
//得到當前的position
temp=buttonView.getId();
}else{
temp=-1;
}

}
});

『肆』 android怎麼用代碼給checkbox設置style-CSDN論壇

1、首先res/drawable中定義編寫如下樣式:

Java代碼
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/check_true" android:state_checked="true"></item>
<item android:drawable="@drawable/check_true" android:state_selected="true"></item>
<item android:drawable="@drawable/check_true" android:state_pressed="true"></item>
<item android:drawable="@drawable/check_false"></item>
</selector>

2、在layout中添加checkbox控制項:

Java代碼

<CheckBox
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_check"
android:button="@null"
android:checked="true"/>

『伍』 android中的checkbox如何設置橫向顯示

這是設置方面的問題,LinearLayout有一個屬性,是整個layout內View的排列方向的,
android:orientation="vertical",為豎向的,默認。
android:orientation="horizontal",才為橫向的,
你需在Layout的xml配置上加上這句才可以的。

『陸』 android checkbox 怎麼設置復選框的只讀效果不讓用戶勾選

提到只讀,很容易想到使用readonly屬性,但是對於復選框來說,這個屬性和期望得到的效果是有差別的。原因在於readonly屬性關聯的是頁面元素的value屬性(例如textbox,設置了readonly就不能修改輸入框的文本內容),而復選框的勾選/取消並不改變其value屬性,改變的只是一個checked狀態。所以對於checkbox來說,設置了readonly,仍然是可以勾選/取消的。效果如下:
<input
type="text"
name="realname"
value="只讀的文本內容..."
readonly="readonly"
/>
<input
type="checkbox"
name="optiona"
readonly="readonly"
/>option
a
<input
type="checkbox"
name="optionb"
readonly="readonly"
/>option
b
<input
type="checkbox"
name="optionc"
readonly="readonly"
/>option
c
option
a
option
b
option
c
和readonly類似的,還有一個disabled屬性,這個屬性的作用是設置頁面元素為不可用,即不可進行任何交互操作(包括不可修改value屬性、不可修改checked狀態等)。效果如下:
<input
type="text"
name="realname"
value="輸入的文本內容..."
disabled="disabled"
/>
<input
type="checkbox"
name="optiona"
disabled="disabled"
/>option
a
<input
type="checkbox"
name="optionb"
disabled="disabled"
/>option
b
<input
type="checkbox"
name="optionc"
disabled="disabled"
/>option
c
option
a
option
b
option
c
從上面我們可以看到,無論是readonly還是disabled,都沒有實現我們期望的效果。既然直接實現不了,那麼我們可以變通一下,模擬實現。代碼如下:
<input
type="checkbox"
name="chkAllowed"
onclick="return
false;"
checked="checked"
/>

『柒』 Android中的checkBOX在代碼中怎麼設置至少選中一個

CheckBox和Button一樣,是android系統提供的最原始的控制項,它的優點在於,不用用戶去填寫具體的信息,只需輕輕點擊,缺點在於只有「是」和「否」兩種情況,但我們往往利用它的這個特性,來獲取用戶的一些信息。
1.CheckBox的常用屬性
checked屬性是CheckBox最重要的屬性之一,改變方式有兩種,xml中定義
android:checked="true|false"
表示選中和不選中
2.在代碼中設置選擇狀態
checkBox.setChecked(true|false);
3.獲取CheckBox的狀態
checkBox.isChecked();
true表示選中,false表示未選中
4.checkBox的應用
1.如果不確定某一組選項有幾個的時候,例如多選之前刪除,那麼要使用listView
+
adapter
其中checkBox存放在listView的adapter中,代碼實現比較復雜,需要自己去注冊checkBox的事件
2.如果checkBox的選項是已經知的,例如興趣愛好,已知有多少個選項的情況下,那麼你只需要用個線性布局做為容器,將checkBox都放到這個容器中
3.獲取選中的文本
如果是用listView的話,只需要自己在adapter中寫一個方法,返回選中的數據即可得到文本,如果是其它容器做的話,只能去遍歷這個布局下的所有checkBox
然後調用
if(checkBox.isChecked()){
checkBox.getText().toString();
//即可得到選中的文本
}
有關checkBox的更多用法,建議查看官網API文檔

熱點內容
頻率計源碼 發布:2024-09-08 07:40:26 瀏覽:778
奧迪a6哪個配置帶後排加熱 發布:2024-09-08 07:06:32 瀏覽:100
linux修改apache埠 發布:2024-09-08 07:05:49 瀏覽:208
有多少個不同的密碼子 發布:2024-09-08 07:00:46 瀏覽:566
linux搭建mysql伺服器配置 發布:2024-09-08 06:50:02 瀏覽:995
加上www不能訪問 發布:2024-09-08 06:39:52 瀏覽:811
銀行支付密碼器怎麼用 發布:2024-09-08 06:39:52 瀏覽:513
蘋果手機清理瀏覽器緩存怎麼清理緩存 發布:2024-09-08 06:31:32 瀏覽:554
雲伺服器的優點與缺點 發布:2024-09-08 06:30:34 瀏覽:734
上傳下載賺錢 發布:2024-09-08 06:14:51 瀏覽:258