自定义CheckBox
来源:互联网 发布:蓝狐科技网络 编辑:程序博客网 时间:2024/04/29 12:18
因为需要,需要自己定义个CheckBox。
1.定义checkboxtestxml.xml
<?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:orientation="vertical" > <CheckBox android:id="@+id/checkboxxml_CB1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/mcheckbox" android:button="@null" /> </LinearLayout>
2.定义里面的mcheckbox.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_checked="true" android:drawable="@drawable/checkbox_select"></item> <item android:state_selected="true" android:drawable="@drawable/checkbox_select"></item> <item android:state_checked="false" android:drawable="@drawable/checkbox"></item></selector>
3.java代码:
import com.login.login.R;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.Toast;public class CheckboxTestActivity extends Activity {private CheckBox checkboxxml_CB1;private Context context = CheckboxTestActivity.this;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.checkboxtestxml);init();}private void init() {checkboxxml_CB1 = (CheckBox) findViewById(R.id.checkboxxml_CB1);checkboxxml_CB1.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if(isChecked){Toast.makeText(context, "选择了", 2).show();}else{Toast.makeText(context, "没选择", 2).show();}}});}}
图片资源直接在百度上面找吧,就2个,一个是选中状态的,一个是没选中的。
注意点:
1.另外必须将android:button设置为@null
0 0
- 自定义CheckBox
- 自定义checkBox
- 自定义CheckBox
- 自定义checkbox
- 自定义CheckBox
- 自定义checkbox
- 自定义checkbox
- 自定义checkbox
- 自定义checkbox
- CheckBox 自定义
- 自定义CheckBox
- 自定义CheckBox
- 自定义checkbox,自定义button
- 自定义 checkbox 样式
- 如何自定义checkbox
- android CheckBox 自定义样式
- 自定义checkbox in iOS
- android自定义checkbox
- Dijkstra
- 20140313
- struts1(8)----将formbean数据封装到实体
- JPA 2 | Dynamic Queries Vs Named Queries
- ios 状态栏设置成黑底前白的方法
- 自定义CheckBox
- cocos2d-x:如何通过命令行上传文件
- C/C++函数调用过程分析
- C#剪切板编程操作图片、音乐、txt==文件(神样的代码,找了好久)
- (转)移动应用趋势中安全占有怎样的地位?
- iOS - 检测耳机孔是否存在耳机:
- POJ 1056 IMMEDIATE DECODABILITY
- hive大数据倾斜总结
- How to read Dalvik SIGQUIT output