自定义EditText形状 和自定义Checkbox
来源:互联网 发布:浙江2017年专升本数据 编辑:程序博客网 时间:2024/06/05 07:13
一 自定义EditText
<EditText android:id="@+id/etSearch" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/button_search" />
button_search.xml 来定制EditText的形状
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- 填充透明颜色 --> <solid android:color="@color/white" /> <!-- 定义边框线条 --> <stroke android:width="1dp" android:color="@color/gray" /> <!-- 圆角角度 --> <corners android:radius="5dp"/> <padding android:bottom="5dp" android:top="5dp" android:left="5dp" android:right="5dp"/></shape>效果图
二 自定义CheckBox
CheckBox和Button一样,也是一种古老的控件,它的优点在于,不用用户去填写具体的信息,只需轻轻点击,缺点在于只有“是”和“否”两种情况,但我们往往利用它的这个特性,来获取用户的一些信息。
checkBox是由两部分组成的,一部分是前面的选择框,还有一个文本内容。要只使用选择框时,需要另 android:button="@bull"。
默认的情况下
<CheckBox25 android:id="@+id/checkbox2"26 android:layout_width="match_parent"27 android:layout_height="wrap_content"28 android:text="应用程序是在平等的条件下创建的" > 29 </CheckBox>
自定义
<CheckBox android:id="@+id/choose_all_cb" android:layout_width="wrap_content" android:layout_height="wrap_content" <span style="white-space:pre"></span>android:textSize="@dimen/content_size" android:paddingLeft="13dp" android:paddingRight="13dp" android:layout_gravity="center" android:button="@null" // 使原生态的checkbox消失 android:drawableLeft="@drawable/checkbox_checked_bg" 使用新的checkbox图片 android:checked="false" />checkbox_checked_bg.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="@mipmap/checkbox_checked"></item> <item android:state_checked="false" android:drawable="@mipmap/checkbox_unchecked"></item></selector>
最后在Activity中设置监听
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ // editText1.setText(buttonView.getText()+"选中"); }else{ //editText1.setText(buttonView.getText()+"取消选中"); } } });
0 0
- 自定义EditText形状 和自定义Checkbox
- EditText自定义边框、虚线、圆角、形状的实现
- 自定义的radioGroup和自定义的editText
- 创建自定义形状的窗体和控件
- 安卓自定义按钮图片 和形状
- 自定义checkbox和radio样式
- RadioButton和CheckBox自定义样式
- RadioButton和CheckBox自定义样式
- 自定义checkbox和点击效果
- EditText自定义
- 自定义EditText
- 自定义EditText
- 自定义EditText
- 自定义EditText
- 自定义EditText
- 自定义EditText
- 自定义CheckBox
- 自定义checkBox
- IOS获取网络图片的尺寸
- Bean named must be of type , but was actually of type
- 错误1error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead.
- makefile函数
- ScrollViewer滚动到底来触发加载数据的Behavior
- 自定义EditText形状 和自定义Checkbox
- 黑马程序员——IO流篇
- IOS实现高斯模糊
- leetcode: Summary Ranges
- 一张图看尽 Linux 内核运行原理
- IOS实现背景色渐变
- JQuery用户登录时的检测
- javascript js undefined null 0 false void(0) NaN 空字符串 比较 区别
- 制作OpenStack Windows Server 2012镜像