<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp" > <CheckBox
android:id="@+id/ck_system"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:checked="false"
android:text="这是系统的CheckBox"
android:textColor="#000000"
android:textSize="17sp" /> <CheckBox
android:id="@+id/ck_custom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@drawable/checkbox_selector"
android:padding="10dp"
android:checked="false"
android:text="这个CheckBox换了图标"
android:textColor="#000000"
android:textSize="17sp" /> </LinearLayout>
java
package com.example.alimjan.hello_world; import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.CheckBox;
import android.widget.CompoundButton; /**
* Created by alimjan on 7/2/2017.
*/ public class class_3_2_1 extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.code_3_2_1);
CheckBox ck_system = (CheckBox) findViewById(R.id.ck_system);
CheckBox ck_custom = (CheckBox) findViewById(R.id.ck_custom);
ck_system.setOnCheckedChangeListener(this);
ck_custom.setOnCheckedChangeListener(this);
} @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String desc = String.format("您%s了这个CheckBox", isChecked?"勾选":"取消勾选");
buttonView.setText(desc);
} public static void startHome(Context mContext) {
Intent intent = new Intent(mContext, class_3_2_1.class);
mContext.startActivity(intent);
} }