选中时和未选中时的背景颜色和文字颜色的改变
2017-12-27 23:53
441 查看
1.在你的项目Res--drawable--选中右键new--Drawable resource file
2.在里面写代码
3.在布局中调用
4.这是另外一个的用法 接着就是往里面添加代码
5.在布局中调用
6.EditText输入时改变颜色 drawable文件夹内的my_image.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true" android:color="#f44" />
<item android:state_focused="false" android:color="#111" />
</selector>
7.在布局中使用
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/my_image"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/my_image"
/>
</LinearLayout>
2.在里面写代码
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <!--true 是你选中时的状态 drawable="@color/baise" 这里你也可以换成一张图片--> <item android:drawable="@color/baise" android:state_checked="true" /> <item android:drawable="@color/lanse" android:state_checked="false" /> </selector>
3.在布局中调用
4.这是另外一个的用法 接着就是往里面添加代码
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 这个是设置控件的圆角--> <corners android:topLeftRadius="4dp" android:topRightRadius="4dp" android:bottomRightRadius="4dp" android:bottomLeftRadius="4dp"/> <!--这是给控件描边--> <stroke android:width="0.1dp" android:color="#f5f5f5" ></stroke> <!--这是设置背景或者文字颜色--> <solid android:color="#f5f5f5" /> </shape>
5.在布局中调用
6.EditText输入时改变颜色 drawable文件夹内的my_image.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true" android:color="#f44" />
<item android:state_focused="false" android:color="#111" />
</selector>
7.在布局中使用
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/my_image"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@drawable/my_image"
/>
</LinearLayout>
相关文章推荐
- IOS UITabBar+UINavigation(改变背景/标题文字颜色、状态图片、tabbar选中方形背景、item间距)
- css 选择后更改文字背景 CSS3 实现改变默认文本选中的颜色
- Android RadioButton设置选中时文字和背景颜色同时改变
- CSS:改变用户选中文字的颜色和背景颜色
- 改变选中区域的文字和背景颜色
- 转 Android RadioButton设置选中时文字和背景颜色同时改变
- CSS3特性之-----改变在浏览器上选中文字时,默认的背景颜色和文字颜色
- 改变文字选中时背景颜色
- CSS改变网页中鼠标选中文字背景颜色例子
- CSS改变被鼠标选中的文字颜色及背景
- Android RadioButton设置选中时文字和背景颜色同时改变
- 怎样设置JTextArea 文本域中选中的文字的颜色和选择区域背景颜色
- TextView点击后背景颜色、文字颜色改变
- android 自定义 radiobutton 文字颜色随选中状态而改变
- android 自定义 radiobutton 文字颜色随选中状态而改变
- 选中的文字的背景变成别的颜色
- css3 ::selection的用法(改变选中文本的背景颜色或者文本颜色)
- IOS7改变状态栏文字的颜色以及导航栏背景颜色
- Axure8.0 按钮选中时改变颜色和文字
- 如何改变状态栏文字和背景颜色