安卓系统机顶盒中如何自由移动程序的焦点(没测试过)
2013-11-17 22:46
225 查看
安卓系统机顶盒中如何自由移动程序的焦点(http://hi.baidu.com/perxiaozi/item/298d37c327a3995ebdef69c4)
还记得自己当初做基于安卓系统的机顶盒程序的时候一直犯困于无法自己控制焦点的移动,在这里小弟分享一下如何自由的移动界面中不同控件的焦点:
例如:我们要把Gridview中item控件的焦点通过遥控器移动到界面中的一个TextView上,让TextView控件高亮显示
第一步:我们要重写TextView控件
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.TextView;
public class DyneTextView extends TextView {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
// TODO Auto-generated method stub
super.onFocusChanged(focused, direction, previouslyFocusedRect);
//此处为该控件获得焦点后高亮显示
if(focused)
{
setBackgroundColor(Color.rgb(255,138,0));
}else
{
//此处为去掉控件高亮显示
setBackgroundColor(0);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.d("onkeydown", "onkeydown");
return super.onKeyDown(keyCode, event);
}
public DyneTextView(Context context) {
super(context);
}
public DyneTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DyneTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
}
接下来就是在xml布局文件中使用该控件了,在使用的时候一定要设置:android:focusable="true"
注:据我观察如果不设置以上属性:ImageView、TextView这些控件只会获取焦点不会高亮显示。
好了,就这样,机顶盒上面的焦点我们就可以自由的控制了。
相关文章推荐
- postconf 命令常用参数
- uva 10026 Shoemaker's Problem
- css优先权问题
- SWT/JFace开发遇到org.eclipse.core.runtime.IProgressMonitor问题的解决办法(转载)
- getOutputStream() 的问题
- C-常用字符串操作函数详解
- 经典设计:17个最有效的学习着陆页设计的例子
- Linux命令-----grep不查找隐藏文件夹的方法
- 方维购物分享系统怎么样,方维系统安全性检测
- 数据库事务实现之checkpoint
- Grep命令详解
- C语言中输出没有重复的数字
- css div的水平、垂直同时居中
- 分享精神
- 思科交换机端口安全的总结
- android学习笔记01
- 重复安装Lync导致发布拓扑失败
- 大型网站架构不得不考虑的10个问题
- Linux命令--sort
- Python之美[从菜鸟到高手]--urlparse源码分析