導航:首頁 > 操作系統 > android復選框樣式

android復選框樣式

發布時間:2023-06-03 13:37:03

Ⅰ 大家好跪求,用安卓實現一個復選框選中另一個復選框默認選中,代碼怎麼寫呢

在你的選項中加入 android:checked="true" 這樣的代碼也就是默認選中

例如:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="愛好:"
android:width="50px"
android:height="30px" />
<CheckBox android:text="籃球"
android:id="@+id/like1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox android:text="足球"
android:id="@+id/like2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"/> //我在足球這里加了個默認選中
<CheckBox android:text="下棋"
android:id="@+id/like3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<CheckBox android:text="游泳"
android:id="@+id/like4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

Ⅱ android中的checkbox如何設置橫向顯示

LinearLayout有一個屬性,是整個layout內View的排列方向的
android:orientation="vertical",為豎向的,默認。

android:orientation="horizontal",才為橫向的

你需在Layout的xml配置上加上這句

Ⅲ 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樣式

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中所彈出的對話框顯示出復選框所選擇的內容

AlertDialog.Builder有現成的API可以實現顯示復選框的內容。
1.創建AlertDialog.Builder並設置數據源
AlertDialog.Builder builder = new Builder(context);
builder.setTitle("復選框"); //設置對話框標題
builder.setIcon(android.R.drawable.ic_menu_more); //設置對話框標題前的圖標

final String[] data = getResources().getStringArray(R.array.radio); //通過resources 得到strings.xml中的字元串數組
boolean[] state = new boolean[data.length];
for(int i=0; i<data.length; i++){
state[i] = sboolean.get(i); //將狀態集合中的數據取出來,下次選擇時候會默認選中
}

2.注冊點擊事件,並記錄復選的數據
/*
* 第一個參數是,數據原,可以是數組,也可以傳strings.xml那的字元串ID,但是建議用數組,因為多選監聽返回的是數組的標下
* 第二個參數是,默認的選中位置,是個boolean數組,對應item的位置
* 第三個是列表點擊監聽事件
*/
builder.setMultiChoiceItems(R.array.radio, state, new DialogInterface.OnMultiChoiceClickListener() {//注冊單選擇監聽事件
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if(isChecked){
Toast.makeText(context,"你選擇了: " + data[which], Toast.LENGTH_SHORT).show();
checkBoxData.add(data[which]); //選擇的時候要保存起來
}else{
Toast.makeText(context,"你取消了: " + data[which], Toast.LENGTH_SHORT).show();
checkBoxData.remove(data[which]); //取消選中的時候要刪除掉
}
sboolean.put(which, isChecked); //每次選擇都要記錄下這個item的狀態
}
});

3.增加確定和取消按鍵
builder.setPositiveButton("確認", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "你點了確定,選擇的是: " + checkBoxData.toString(), Toast.LENGTH_SHORT).show();
}
});

4.設置dialog的相關參數,並彈出
builder.setNegativeButton("取消", null); //取消不做任何處理
builder.setCancelable(true); //設置按鈕是否可以按返回鍵取消,false則不可以取消
AlertDialog dialog = builder.create(); //創建對話框
dialog.setCanceledOnTouchOutside(true); //設置彈出框失去焦點是否隱藏,即點擊屏蔽其它地方是否隱藏
dialog.show();

Ⅵ android怎麼讓復選框實現單選框功能

1單擊左上角office圖標。選擇彈出的對話框的 右下角的 word選項 2.在 word選項卡中選擇 在功能區顯示開發工具選項卡 打勾,確定。 3.在菜單欄中找到開發工具選項卡。。。在控制項的欄中。選擇控制項。單眩復眩下拉菜單等等都在 這里 。

閱讀全文

與android復選框樣式相關的資料

熱點內容
手機上pdf怎麼加密碼 瀏覽:1000
51單片機hex文件 瀏覽:328
vsc怎麼編譯bin 瀏覽:5
安卓基站延遲怎麼辦 瀏覽:543
亞馬遜店鋪可以遷移到雲伺服器嗎 瀏覽:840
真空泵壓縮比會改變嗎 瀏覽:329
示波器app怎麼看 瀏覽:612
米家app英文怎麼改 瀏覽:605
學習編程你有什麼夢想 瀏覽:886
農行信用報告解壓密碼 瀏覽:217
小程序員調試信息 瀏覽:183
電腦打代碼自帶編譯嗎 瀏覽:273
和平怎麼在和平營地轉安卓 瀏覽:463
我的世界中如何查看伺服器的人數 瀏覽:618
台式機改為網路伺服器有什麼好處 瀏覽:960
騰訊雲輕量應用伺服器如何登陸 瀏覽:620
考研復試c語言編譯器 瀏覽:150
安卓的字體怎麼變粗 瀏覽:253
java錯誤無法載入主類 瀏覽:348
程序員考試考什麼文憑 瀏覽:883