标签:package log xmlns end void pat box instance desc
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:layout_width="match_parent" 3 android:layout_height="match_parent" 4 android:orientation="vertical" 5 android:padding="10dp" > 6 7 <CheckBox 8 android:id="@+id/ck_system" 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content" 11 android:padding="10dp" 12 android:checked="false" 13 android:text="这是系统的CheckBox" 14 android:textColor="#000000" 15 android:textSize="17sp" /> 16 17 <CheckBox 18 android:id="@+id/ck_custom" 19 android:layout_width="match_parent" 20 android:layout_height="wrap_content" 21 android:button="@drawable/checkbox_selector" 22 android:padding="10dp" 23 android:checked="false" 24 android:text="这个CheckBox换了图标" 25 android:textColor="#000000" 26 android:textSize="17sp" /> 27 28 </LinearLayout>
java
1 package com.example.alimjan.hello_world; 2 3 import android.content.Context; 4 import android.content.Intent; 5 import android.os.Bundle; 6 import android.support.v7.app.AppCompatActivity; 7 import android.widget.CheckBox; 8 import android.widget.CompoundButton; 9 10 /** 11 * Created by alimjan on 7/2/2017. 12 */ 13 14 public class class_3_2_1 extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener { 15 16 @Override 17 protected void onCreate(Bundle savedInstanceState) { 18 super.onCreate(savedInstanceState); 19 setContentView(R.layout.code_3_2_1); 20 CheckBox ck_system = (CheckBox) findViewById(R.id.ck_system); 21 CheckBox ck_custom = (CheckBox) findViewById(R.id.ck_custom); 22 ck_system.setOnCheckedChangeListener(this); 23 ck_custom.setOnCheckedChangeListener(this); 24 } 25 26 @Override 27 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 28 String desc = String.format("您%s了这个CheckBox", isChecked?"勾选":"取消勾选"); 29 buttonView.setText(desc); 30 } 31 32 public static void startHome(Context mContext) { 33 Intent intent = new Intent(mContext, class_3_2_1.class); 34 mContext.startActivity(intent); 35 } 36 37 }
标签:package log xmlns end void pat box instance desc
原文地址:http://www.cnblogs.com/alimjan/p/7105849.html