我实现了自定义列表视图,但现在没有选择元素的视觉反馈。我认为这是微不足道的,但我找不到任何内容 - 任何人都可以提供有关如何将默认的UI元素焦点行为应用到我的listview项目的提示吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true">
<TextView android:id="@+id/list_item"
android:layout_gravity="center_vertical"
android:layout_width="0dip"
android:layout_weight="1.0"
android:textSize="20sp"
android:textColor="#FFFFFFFF"
android:layout_height="wrap_content"
android:padding="20dp"/>
</LinearLayout>
从目前为止我得到的回复来看,我想我应该澄清一下我要做的事情:我想模仿listview项目(在标准用户界面中)长时间按下的行为。当你穿过它时,它并没有真正做任何事情,但是在触摸项目并持续任何时间时,它会变成颜色[橙色,在我的情况下]然后快速过渡到白色。
而且,经过进一步检查,我认为只有在添加上下文菜单时才会发生这种情况 - 我会尝试一下并使用结果对其进行编辑。
答案 0 :(得分:1)
您可能需要查看Touch Mode上的文章。
答案 1 :(得分:1)
执行此操作的方法是添加上下文菜单。这将带来我期望的效果。
答案 2 :(得分:0)
您可以尝试为listview行背景设置一个drawable选择器。
android:background="@drawable/listview_bg"
drawable需要是这样的:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/list_bg_blue"/>
<item android:state_pressed="true" android:state_enabled="false" android:drawable="@drawable/list_bg_blue"/>
<item android:state_pressed="true" android:state_enabled="true" android:drawable="@drawable/list_bg_blue"/>
<item android:state_enabled="false" android:drawable="@drawable/list_bg_blue"/>
<item android:drawable="@drawable/list_bg_grey"/>
另外,请尝试使用RelativeLayout而不是LinearLayout。