自定义获取焦点的TextView
自定义控件编写流程
创建一个默认就能获取焦点的TextView
1.创建一个类继承至TextView,FocusTextView
2.重写其构造方法
//使用在通过java代码创建控件
public FocusTextView(Context context) {
super(context);
} //由系统调用(带属性+上下文环境构造方法)
public FocusTextView(Context context, AttributeSet attrs) {
super(context, attrs);
} //由系统调用(带属性+上下文环境构造方法+布局文件中定义样式文件构造方法)
public FocusTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
3.将原有TextView上的isFocus方法默认修改为,能够获取焦点
//重写获取焦点的方法,由系统调用,调用的时候默认就能获取焦点
@Override
public boolean isFocused() {
return true;
}
4.使用过程
获取当前类的全路径名称,作为xml中的标签存在,其余属性的使用方式和TextView一致
public class FocusTextView extends TextView {
//使用在通过java代码创建控件
public FocusTextView(Context context) {
super(context);
}
//由系统调用(带属性+上下文环境构造方法)
public FocusTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
//由系统调用(带属性+上下文环境构造方法+布局文件中定义样式文件构造方法)
public FocusTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
//重写获取焦点的方法,由系统调用,调用的时候默认就能获取焦点
@Override
public boolean isFocused() {
return true;
}
}
<!-- android:ellipsize="end"添加省略点的所在位置 -->
<!-- 想让文字出现跑马灯效果,必须让其获取焦点 -->
<!-- android:marqueeRepeatLimit="marquee_forever"一直滚动属性 -->
<!-- 自定义控件达到滚动效果(其实就是重新原有的TextView,让其一直能够获取焦点即可) -->
<!--
<TextView
android:text="秋天秋天悄悄过去,留下小秘密,啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"
android:textColor="#000"
android:singleLine="true"
android:padding="5dp"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
--> <com.itheima.mobilesafe74.view.FocusTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:padding="5dp"
android:singleLine="true"
android:text="秋天秋天悄悄过去,留下小秘密,啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"
android:textColor="#000" >
</com.itheima.mobilesafe74.view.FocusTextView>
自定义获取焦点的TextView的更多相关文章
- Android 手机卫士--自定义控件(获取焦点的TextView)
本文地址:http://www.cnblogs.com/wuyudong/p/5906735.html,转载请注明源地址. 本文将实现标题栏下面的textview中的文字跑马灯的效果,就是将一行文字水 ...
- Android项目实战(十):自定义倒计时的TextView
项目总结 -------------------------------------------------------------------------------------------- 有这 ...
- Android自定义之TextView跑马灯的监听
TextView都有跑马灯的效果,如果说让你去监听跑马灯效果的执行,我觉得这个需求有点二了,但是也要实现. 思路: 1.自定义View 继承TextView 这种方法过于麻烦,只是监听一个跑马灯 ...
- [置顶] android 自定义TextView
系统自带的控件TextView有时候没满一行就换行了,为了解决这个问题,自定义了一个TextView,只有一行显示不完全的情况下才会去换行显示,代码如下: package com.open.textv ...
- vue自定义指令获取焦点及过滤器修改时间
<template id="comp3"> <div id="app"> <model :list="selectedl ...
- android标题栏下面弹出提示框(一) TextView实现,带动画效果
产品经理用的是ios手机,于是android就走上了模仿的道路.做这个东西也走了一些弯路,写一篇博客放在这里,以后自己也可用参考,也方便别人学习. 弯路: 1.刚开始本来用PopupWindow去实现 ...
- 站在巨人的肩膀上---重新自定义 android- ExpandableListView 收缩类,实现列表的可收缩扩展
距离上次更新博客,时隔略长,诸事繁琐,赶在去广州答辩之前,分享下安卓 android 中的一个 列表收缩 类---ExpandableListView 先上效果图: 如果想直接看实现此页面的代码请下滑 ...
- 自定义样式RatingBar的使用
1.设置布局文件,自定义ratingbar样式 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/an ...
- Android自定义View
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24252901 很多的Android入门程序猿来说对于Android自定义View ...
随机推荐
- python正则表达式之元字符介绍
python中元字符及其含义如下: 元字符 含义 . 匹配除换行符以外的任意一个字符 ^ 匹配行首 $ 匹配行尾 ? 重复匹配0次或1次 * 重复匹配0次或更多次 + 重复匹配1次或更多次 {n,} ...
- Android调试常用的工具简单介绍
配置Android环境的时候,我们需要安装sdk.在sdk的目录下: platform-tools 目录下的adb tool下的: ddms.bat adb :可以cd 当前目录,然后使用相应的命令, ...
- YTU 2344: 先序遍历二叉树
原文链接:https://www.dreamwings.cn/ytu2344/2603.html 2344: 先序遍历二叉树 时间限制: 1 Sec 内存限制: 128 MB 提交: 4 解决: ...
- Capturing Audio & Video in HTML5
使用HTML5抓取 Audio & Video 原文地址: http://www.html5rocks.com/en/tutorials/getusermedia/intro/ 本地化的文章: ...
- poj3342 Party at Hali-Bula
树形dp题,状态转移方程应该很好推,但一定要细心. http://poj.org/problem?id=3342 #include <cstdio> #include <cstrin ...
- JAVA基础知识之Map集合
Map的内部结构Entry Set与Map的关系 Map的内部类Entry Map的通用方法及Map的简单用法 HashMap和HashTable的区别 HashMap和HashTable判断元素相等 ...
- 调试器不能连接到STM32的问题与解决办法
很多人都碰到过调试器不能连接到STM32的问题,不管是IAR的J-Link还是Keil的ULink,或者是ST的ST-Link.出现这个问题时,调试软件会提示不能建立与Cortex-M3的连接,或提示 ...
- 几篇不错的基础css博客转载
CSS 巧用 :before和:after:http://web.jobbole.com/85083/ css清除元素间距:http://ouvens.github.io/frontend-css/2 ...
- android导入项目出现style错误,menu错误
android导入项目出现style错误,menu错误 style //查看 res/values/styles.xml 下的报错点. <style name="AppBaseThem ...
- 使用FindFirstFile,FindNextFile遍历一个文件夹
//遍历文件夹函数 void TraverseFolder(LPCTSTR lpPath) { TCHAR szFind[MAX_PATH] = {_T("\0")}; WIN32 ...