您的位置:首页 > 移动开发 > Android开发

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"

/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: