自定义控件编写流程
创建一个默认就能获取焦点的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的更多相关文章

  1. Android 手机卫士--自定义控件(获取焦点的TextView)

    本文地址:http://www.cnblogs.com/wuyudong/p/5906735.html,转载请注明源地址. 本文将实现标题栏下面的textview中的文字跑马灯的效果,就是将一行文字水 ...

  2. Android项目实战(十):自定义倒计时的TextView

    项目总结 -------------------------------------------------------------------------------------------- 有这 ...

  3. Android自定义之TextView跑马灯的监听

    TextView都有跑马灯的效果,如果说让你去监听跑马灯效果的执行,我觉得这个需求有点二了,但是也要实现. 思路: 1.自定义View  继承TextView   这种方法过于麻烦,只是监听一个跑马灯 ...

  4. [置顶] android 自定义TextView

    系统自带的控件TextView有时候没满一行就换行了,为了解决这个问题,自定义了一个TextView,只有一行显示不完全的情况下才会去换行显示,代码如下: package com.open.textv ...

  5. vue自定义指令获取焦点及过滤器修改时间

    <template id="comp3"> <div id="app"> <model :list="selectedl ...

  6. android标题栏下面弹出提示框(一) TextView实现,带动画效果

    产品经理用的是ios手机,于是android就走上了模仿的道路.做这个东西也走了一些弯路,写一篇博客放在这里,以后自己也可用参考,也方便别人学习. 弯路: 1.刚开始本来用PopupWindow去实现 ...

  7. 站在巨人的肩膀上---重新自定义 android- ExpandableListView 收缩类,实现列表的可收缩扩展

    距离上次更新博客,时隔略长,诸事繁琐,赶在去广州答辩之前,分享下安卓 android 中的一个 列表收缩 类---ExpandableListView 先上效果图: 如果想直接看实现此页面的代码请下滑 ...

  8. 自定义样式RatingBar的使用

    1.设置布局文件,自定义ratingbar样式 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/an ...

  9. Android自定义View

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24252901 很多的Android入门程序猿来说对于Android自定义View ...

随机推荐

  1. 每日一九度之 题目1023:EXCEL排序

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:18804 解决:4240 题目描述:     Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能.     对每个测试用例 ...

  2. 20150618_Andriod _set Dialog_弹出式菜单

    参考地址: http://blog.csdn.net/zhyl8157121/article/details/8169172                   http://blog.csdn.ne ...

  3. Out of Hay

    Out of Hay Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13094 Accepted: 5078 Descripti ...

  4. 对于数据包的截取,使用linux中的netfilter钩子函数

    http://blog.csdn.net/wswifth/article/details/5115358 在师哥的代码(packet.c)中使用的是Linux2.4内核中的一个子系统:netfilte ...

  5. Poj(1459),最大流,EK算法

    题目链接:http://poj.org/problem?id=1459 Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Su ...

  6. 2016 Al-Baath University Training Camp Contest-1 H

     Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...

  7. Codeforces Round #260 (Div. 2) B

    Description Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expre ...

  8. 2016年6月25日 星期六 --出埃及记 Exodus 14:22

    2016年6月25日 星期六 --出埃及记 Exodus 14:22 and the Israelites went through the sea on dry ground, with a wal ...

  9. ASCII字符表

  10. An Example Of Validating Text Item In Oracle Forms Using When-Validate-Item Trigger

    Example is given below to validate a Text Item in Oracle Forms with specific rules condition which c ...