亚洲高清vr播放在线观看,欧美亚洲精品免费,欧美日韩天堂在线视频,午夜福利小视频

      學(xué)習(xí)啦 > 知識大全 > 知識百科 > 公共基礎(chǔ)知識 > 安卓checkbox的用法Android平臺優(yōu)勢

      安卓checkbox的用法Android平臺優(yōu)勢

      時(shí)間: 謝君787 分享

      安卓checkbox的用法Android平臺優(yōu)勢

        安卓開發(fā)中經(jīng)常會(huì)用到checkbox,那么具體是如何使用的呢?以下是由學(xué)習(xí)啦小編整理關(guān)于安卓checkbox的用法的內(nèi)容,希望大家喜歡!

        安卓checkbox的用法

        CheckBox定義一個(gè)同意協(xié)議的按鈕,只要同意button才可以點(diǎn)擊

        XML代碼

        <CheckBox

        android:id="@+id/checkbox1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_above="@+id/button1"

        android:layout_alignLeft="@+id/linearLayout1"

        android:text="牛仔"

        />

        在onClick里面設(shè)置只要當(dāng)checkbox.isChecked()為true,也就是勾選上時(shí),button1.setEnabled(true);才可以點(diǎn)擊

        java代碼

        checkbox = (CheckBox) findViewById(R.id.checkbox1);

        checkbox.setChecked(false);

        button1.setEnabled(false);

        checkbox.setOnClickListener(new CheckBox.OnClickListener(){

        <span style="white-space:pre"> </span>@Override

        public void onClick(View v) {

        // TODO Auto-generated method stub

        if(checkbox.isChecked()){

        button1.setEnabled(true);

        }else{

        <span style="white-space:pre"> </span>button1.setEnabled(false);

        }

        <span style="white-space:pre"> </span>}

        });

        定義多個(gè)CheckBox來控制同一個(gè)控件

        XML代碼

        <CheckBox

        android:id="@+id/checkbox1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_above="@+id/button1"

        android:layout_alignLeft="@+id/linearLayout1"

        android:text="牛仔"

        />

        <CheckBox

        android:id="@+id/checkbox2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignBaseline="@+id/checkbox3"

        android:layout_alignBottom="@+id/checkbox3"

        android:layout_marginLeft="27dp"

        android:layout_toRightOf="@+id/checkbox3"

        android:text="面包" />

        <CheckBox

        android:id="@+id/checkbox3"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignBaseline="@+id/checkbox1"

        android:layout_alignBottom="@+id/checkbox1"

        android:layout_toRightOf="@+id/button1"

        android:text="黃油" />

      1697483