标签:
问题:遥控按键选中的选项有跑马灯效果,但是鼠标事件来说,没有跑马灯效果
解题过程:重写一个类继承textview,永远获取焦点,不行。即使我再OnhoverListener里面实现onHover并且对textview获取了焦点,但是仍旧不行
解决方法:最后重写一个类继承textview,永远获取焦点,并且对textview调用了setSelected(true)之后就可以了。
public class MarqueeTextView extends TextView { public MarqueeTextView(Context con) { super(con); } public MarqueeTextView(Context context, AttributeSet attrs) { super(context, attrs); } public MarqueeTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean isFocused() { return true; } @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { } }
<com.jrm.localmm.ui.view.MarqueeTextView android:id="@+id/ListNameTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:gravity="left" android:layout_marginLeft="2dip" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:textColor="@android:color/white" android:textSize="15sp" > </com.jrm.localmm.ui.view.MarqueeTextView>
holder.settingOptionTextView.setSelected(true);
另外总结下AN TV下的鼠标,遥控按键事件:
首先对于selector而言,在TV下面只有遥控按键能够触发全部的事件:focus,selected,press
<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 无焦点状怿--> <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" /> <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/list_foucs" /> <!-- 焦点状怿--> <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/list_foucs" /> <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/list_foucs" /> <!-- 按下状怿--> <item android:state_pressed="true" android:drawable="@drawable/list_foucs" /> </selector>
至于在鼠标操控下要怎么模仿按键事件选择某个item之后,背景图像变化的话 ,只能间接通过设置item的背景图像来实现了
//refresh the focus state of listview item public void refreshItemFocusState(int index) { // TODO Auto-generated method stub Log.d(TAG, "refreshItemFocusState index = "+index) ; currentSelectedItemView = listView.getChildAt(index); if(isEnterListviewLocation){ if(oldSelectedItemView != null) oldSelectedItemView.setBackgroundResource(R.drawable.button_normal) ; if(currentSelectedItemView != null) currentSelectedItemView.setBackgroundResource(R.drawable.list_foucs); oldSelectedItemView = currentSelectedItemView ; } }
[Android TV 按键响应]listview的textview跑马灯在鼠标控制下失效的问题
标签:
原文地址:http://blog.csdn.net/muxidreamtohit/article/details/51337814