不卡AV在线|网页在线观看无码高清|亚洲国产亚洲国产|国产伦精品一区二区三区免费视频

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

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

時間: 謝君787 分享

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

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

  安卓checkbox的用法

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

  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,也就是勾選上時,button1.setEnabled(true);才可以點擊

  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>}

  });

  定義多個CheckBox來控制同一個控件

  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