Android 开发笔记___复选框__checkbox

 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 }
时间: 2024-08-06 20:07:21

Android 开发笔记___复选框__checkbox的相关文章

Android实战之ListView复选框

项目中有用到复选框的例子,啊啊......在网上查找有关资料,大多都是过于繁琐,所以自己决定写个这个方面的demo... 先给个效果图: 在ListView中添加复选框主要注意以下几个问题: 1.ListView item与item中的控件抢焦点的问题(必须设置CheckBox不可点击和不能获取焦点,让ListView得到焦点) 2.ListView的setChoicMode(int choiceMode)选择模式():有choiceMode : CHOICE_MODE_NONE, CHOICE

android menu菜单的复选框

android新手,目前在整在一个android需求,需要集成媒体播放器,  在菜单中添加一个checkbox,当选中checkbox的时候停止播放器,当取消选中的时候启动播放器,目前我已经实现了选中checkbox停止播放器. 当我 取消选中checkbox的时候,报错了,找了好久没找到啥原因.心情很不好..... 我的代码如下: MainActivity 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

Android 开发笔记___存储方式__共享参数__sharedprefences

Android 的数据存储方式有四种,这次是[共享参数__sharedprefences] 听起来挺别扭的,平时看到的app里面,当用户删除了一些软件以后下次安装,发现原来的设置还在,这种情况就是把一些用户的设置保存在手机里面的一个存储区域, 格式是XML key__Value 不方便保存关系比较复杂的数据 write 1 package com.example.alimjan.hello_world; 2 3 /** 4 * Created by alimjan on 7/4/2017. 5

Android 开发笔记___图像视图

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:ori

Android 开发笔记___图像视图__简单截屏

1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 a

Android 开发笔记___滚动视图__scroll view

1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" android:layout_width="match_parent" 4 android:l

Android 开发笔记___图像按钮__imageButton

IMAGEBUTTON 其实派生自image view,而不是派生自button.,image view拥有的属性和方法,image button 统统拥有,只是imagebutton有个默认的按钮外观. image button  只能显示图形 imagebutton 上面的图片可按比例拉伸 只能在背景显示一张图形,但分别在前景和背景显示两张图片,实现图片叠加的效果 在输入法无法输入的字符和特殊字体显示的字符串,就适合用imagebutton,   先切图再显示 要想在文字周围放图片可以用基于

Android 开发笔记___初级控件之实战__计算器

功能简单,实现并不难,对于初学者可以总和了解初级控件的基本使用. 用到的知识点如下: 线性布局 LinearLayout:整体界面是从上往下的,因此需要垂直方向的linearlayout:下面每行四个按钮,需要水平的linearlayout. 滚动视图 ScrollView    :虽然界面不宽也不高,以防万一,有可能会遇到屏幕特别小的手机,因此用一个垂直方向的scrollview. 文本视图 TextView      :上面标题就是一个textview,结果显示也是textview,但是更高

Android 开发笔记___时间选择器---timePicker

像datepicker一样,也有timepicker. 同样有timepickerdialog 所用到的方法还是一样,监听时间选择器的变化. 1 package com.example.alimjan.hello_world; 2 3 import java.util.Calendar; 4 5 /** 6 * Created by alimjan on 7/15/2017. 7 */ 8 9 import android.app.TimePickerDialog; 10 import andr