android TextView selector点击样式改变
来源:互联网 发布:js获取当前时间字符串 编辑:程序博客网 时间:2024/06/07 21:52
1.selector 从单词的意思来说:选择器,就是对你的目标的控制。selector主要是用在ListView的item单击样式和TextView和Button的点击样式。
2.主要属性介绍:
android:state_selected选中
android:state_focused获得焦点
android:state_pressed点击
android:state_enabled设置是否响应事件,指所有事件
3.下面通过例子来说一下selector对TextView设置:
1).在res下创建一个drawable文件夹用于装textselector.xml ,对点击样式的定义放在这里面
2). 将textselector.xml资源加载到TextView上
textselector.xml
<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:color="#45c01a" android:state_pressed="true"/><itemandroid:color="#9a9a9a"/></selector>
activity_main.xml
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"><TextViewandroid:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:paddingBottom="4dp" android:text="首页" android:textColor="@drawable/textselector" android:textSize="20sp"></TextView></LinearLayout>
运行程序之后要看到颜色改变的效果的话,还必须给TextView添加按钮监听事件,就算事件不取执行什么功能都必须去设置。
TextView textView = (TextView) findViewById(R.id.textview); textView.setOnClickListener(null);
阅读全文
0 0
- android TextView selector点击样式改变
- android selector(如对TextView点击样式改变) - perfect亮
- 安卓开发——通过selector实现对TextView点击样式改变
- textView结合selector点击改变文字颜色
- 点击LinearLayout使用selector改变TextView字体颜色
- 点击LinearLayout使用selector改变TextView字体颜色
- 点击LinearLayout使用selector改变TextView字体颜色
- 点击LinearLayout使用selector改变TextView字体颜色
- 点击LinearLayout使用selector改变TextView字体颜色 (转)
- 点击LinearLayout使用selector改变TextView字体颜色
- 点击LinearLayout使用selector改变TextView字体颜色
- android 设置textview获取焦点改变样式
- selector 点击样式
- android selector(改变button,textview,listview的背景图片)
- Android设置TextView的Selector来控制点击的颜色
- Android设置TextView的Selector来控制点击的颜色
- Android设置TextView的Selector来控制点击的颜色
- Android设置TextView的Selector来控制点击的颜色
- Webpack工程化解决方案easywebpack
- okhttp3.internal.http2.StreamResetException: stream was reset: INTERNAL_ERROR
- 我对rxjava的理解
- KV存储的对比
- Linux出现Bash . configure permission denied错误
- android TextView selector点击样式改变
- java 统计文本中出现概率最高的10个字符串
- Java 网络编程
- 日常运维(四):iptables filter表案例 iptables nat表应用
- 【51Nod
- 用一种新奇简单的思想,看待傅里叶变换(原文:如果看了此文你还不懂傅里叶变换,那就过来掐死我吧)
- [BFS] POJ 3126
- 10月31日解题报告
- java对redis基本操作