android 如何设置checkbox、edittext点击前后不同样式
2014-02-27 16:11
676 查看
checkbox
1.首先在drawable文件夹中添加drawable文件checkbox_style.xml。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/duigou" android:state_checked="true"/>
<item android:drawable="@drawable/duigou0" android:state_checked="false"/>
<item android:drawable="@drawable/duigou0" />
</selector>
2.在values文件夹下的styles.xml文件中添加CustomCheckboxTheme样式。
<style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_style</item>
</style>
3.在布局文件中使用CustomCheckboxTheme样式。
<CheckBox
android:id="@+id/remember"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CustomCheckboxTheme"
android:text="@string/remember"/>
//************************************************************************************
edittext
1.首先在drawable文件夹中添加drawable文件editview_style.xml。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/focused" android:state_focused="true" />
<item android:drawable="@drawable/disabled" android:state_focused="false"/>
<item android:drawable="@drawable/disabled" />
</selector>
2.在values文件夹下的styles.xml文件中添加CustomEditviewTheme样式。
<style name="CustomEditviewTheme" parent="@android:style/Widget.EditText">
<item name="android:background">@drawable/editview_style</item>
</style>
3.在布局文件中使用CustomCheckboxTheme样式。
<EditText
style="@style/CustomEditviewTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Contact phone"
android:inputType="phone"
android:id="@+id/EContactphone"
/>
1.首先在drawable文件夹中添加drawable文件checkbox_style.xml。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/duigou" android:state_checked="true"/>
<item android:drawable="@drawable/duigou0" android:state_checked="false"/>
<item android:drawable="@drawable/duigou0" />
</selector>
2.在values文件夹下的styles.xml文件中添加CustomCheckboxTheme样式。
<style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_style</item>
</style>
3.在布局文件中使用CustomCheckboxTheme样式。
<CheckBox
android:id="@+id/remember"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CustomCheckboxTheme"
android:text="@string/remember"/>
//************************************************************************************
edittext
1.首先在drawable文件夹中添加drawable文件editview_style.xml。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/focused" android:state_focused="true" />
<item android:drawable="@drawable/disabled" android:state_focused="false"/>
<item android:drawable="@drawable/disabled" />
</selector>
2.在values文件夹下的styles.xml文件中添加CustomEditviewTheme样式。
<style name="CustomEditviewTheme" parent="@android:style/Widget.EditText">
<item name="android:background">@drawable/editview_style</item>
</style>
3.在布局文件中使用CustomCheckboxTheme样式。
<EditText
style="@style/CustomEditviewTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Contact phone"
android:inputType="phone"
android:id="@+id/EContactphone"
/>
相关文章推荐
- android中通过网络请求数据显示在Listview中,面对许多的item,如何给每个item设置点击事件以跳转到不同的activity
- Android如何设置文字点击事件
- android UI学习 -- 设置界面的布局(包括style的使用,selector的使用,Checkbox自定义样式,菜单项的样式)
- Android中设置checkbox的样式
- android-设置EditText为密码样式
- 前端开发:css技巧,如何设置select、radio 、 checkbox 、file这些不可直接设置的样式 。
- Android——遍历分别设置布局中不同控件的样式
- android如何设置控件的样式
- android 如何设置 EditText 不换行
- Android EditText 光标样式设置
- Android之同一个TextView设置不同样式的文字
- android小技巧之TextView设置不同字体大小及样式
- android中如何设置点击button页面跳转
- android中如何设置Toast 的样式
- Android中checkbox控件的自定义样式设置
- Android 如何将一个Activity设置成窗口样式
- 使用selector设置按钮不同状态的样式(Android)
- [置顶] android,在java代码中,如何给textview设置不同的颜色,以及引用color中资源设置颜色
- Flex中如何给depthColors样式设置一个颜色数组给树Tree控件不同层设置不同颜色的例子
- 如何利用CSS给同一个网页中的超链接设置设置不同的样式?