checkBox

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cb_3"
android:orientation="vertical">
<TextView
android:id="@+id/tv_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="好嗨哟"
android:textSize="20sp"/>
<CheckBox
android:id="@+id/cb_4"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/bg_checkable" 自定义选框的样式
android:paddingLeft="10dp" 选择空间和文字间的距离
android:text="哈哈哈"
android:textSize="20sp"/>
<CheckBox
android:id="@+id/cb_5"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:button="@drawable/bg_checkable"
android:text="嘿嘿嘿"
android:textSize="20sp"/>

</LinearLayout>

 

选框添加触发事件

public class CheckBoxActivity extends AppCompatActivity {

private CheckBox cb4;
private CheckBox cb5;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_box);
cb4= (CheckBox) findViewById(R.id.cb_4);
cb5= (CheckBox) findViewById(R.id.cb_5);

cb4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(CheckBoxActivity.this,isChecked?"4被选中":"4未选中",Toast.LENGTH_LONG).show();
}
});

cb5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(CheckBoxActivity.this,isChecked?"5被选中":"5未选中",Toast.LENGTH_LONG).show();
}
});
}
}
 

转载于:https://www.cnblogs.com/AppTester/p/10045274.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值