日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

android 许可协议,Android 基本控件的使用二(注册许可协议)(CheckBox)

發(fā)布時(shí)間:2024/10/8 Android 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 许可协议,Android 基本控件的使用二(注册许可协议)(CheckBox) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

需要注意的是:按鈕部分,在復(fù)選框選中之前是顯示不可點(diǎn)擊狀態(tài),一旦被選中之后就會(huì)變成可點(diǎn)擊按鈕。

為復(fù)選框設(shè)置的監(jiān)聽(tīng)為:setOnCheckedChangeListener

實(shí)現(xiàn)的方法有兩種:

方法一:在 activity_main.xml 中 中 設(shè)置?android:enabled="false"

在 MainActivity.java 中的代碼為:?submit.setEnabled(isCheckd);

方法二:在 MainActivity.java 中 直接判斷,當(dāng)點(diǎn)了復(fù)選框的時(shí)候,是點(diǎn)擊的;沒(méi)點(diǎn)是不可點(diǎn)擊的

// ?agree 是復(fù)選框的名稱

if(agree.isChecked()){

選中

submit.setEnabled(true);

}else {

submit.setEnabled(false);

}

activity_main.xml

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity">

android:id="@+id/textView1"

android:layout_width="match_parent"

android:layout_height="200dp"

android:text="@string/hello_world"/>

android:id="@+id/cb_agree"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/textView1"

android:layout_below="@+id/textView1"

android:text="我同意以上協(xié)議"/>

android:id="@+id/btn_sumbit"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/cb_agree"

android:layout_below="@+id/cb_agree"

android:enabled="false"

android:text="注冊(cè)"/>

MainActivity.java

package cn.sohpia.andoird;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.CompoundButton;

import android.widget.CompoundButton.OnCheckedChangeListener;

public class MainActivity extends Activity implements OnCheckedChangeListener{

// 聲明控件

private CheckBox agree;

private Button submit;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// 初始化控件

initViews();

// 為復(fù)選框控件設(shè)置監(jiān)聽(tīng)

agree.setOnCheckedChangeListener(this);

}

/**

* 初始化控件

*/

private void initViews() {

agree = (CheckBox) findViewById(R.id.cb_agree);

submit = (Button) findViewById(R.id.btn_sumbit);

}

/**

* 為控件設(shè)置監(jiān)聽(tīng)

*/

@Override

public void onCheckedChanged(CompoundButton btn, boolean isCheckd) {

// 判斷復(fù)選框是否選中

// 如果 在xml 中沒(méi)有設(shè)置 android:enable=flase:則需要些以下代碼

// if(agree.isChecked()){

// 選中

//submit.setEnabled(true);

// }else {

//submit.setEnabled(false);

//}

submit.setEnabled(isCheckd);

}

}

總結(jié)

以上是生活随笔為你收集整理的android 许可协议,Android 基本控件的使用二(注册许可协议)(CheckBox)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。