android - gridview listSelector focusableInTouchMode
问题描述
我正在创建一个由 d-pad 和触摸控制的自定义启动器。为了获得对项目的关注,我为列表选择器设置了一个选择器 XML,并在获得焦点时设置了自定义背景。但是,当我在触摸模式下按下该项目时,它也会获得焦点。
我想以某种方式将列表选择器的 focusableInTouchMode 设置为 false,以便在按下时不显示背景。
网格视图 XML:
<GridView
android:id="@+id/appsContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:clipToPadding="false"
android:columnWidth="@dimen/app_row_column_width"
android:fadingEdge="none"
android:horizontalSpacing="@dimen/app_row_horizontal_spacing"
android:numColumns="auto_fit"
android:overScrollMode="never"
android:listSelector="@drawable/bg_list_selector"
android:focusableInTouchMode="false"
android:paddingTop="@dimen/activity_vertical_margin"
android:scrollbars="none"
android:stretchMode="spacingWidth"
android:verticalSpacing="@dimen/app_row_vertical_spacing"/>
bg_list_selector xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bg_list_item_focused" android:state_focused="true"/>
<!--<item android:drawable="@drawable/bg_list_item_focused" android:state_hovered="true"/>-->
<item android:drawable="@color/full_transparent" android:state_selected="true"/>
<item android:drawable="@color/full_transparent" android:state_pressed="true"/>
<item android:drawable="@color/full_transparent" android:state_window_focused="true"/>
<item android:drawable="@color/full_transparent" />
解决方案
解决方案:
改为将选择器应用于background
项目布局并设置android:listSelector="@null"
.
网格:
<FrameLayout
android:id="@+id/grid_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:id="@+id/categories_grid_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:horizontalSpacing="10dp"
android:numColumns="4"
android:listSelector="@null"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
</FrameLayout>
物品:
<FrameLayout
android:id="@+id/grid_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/list_view_selector">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
推荐阅读
- javascript - React Router如何使用props?
- django - Django 通过 CharField 过滤对象,最多包含两个单词
- json - 如何更新 JObject 中的对象值
- r - 将可选参数传递给函数,三个点
- javascript - Expand 和 useArrows 不适用于 Treepanel
- javascript - jQuery删除具有特定数据属性的整个脚本
- python - Pandas diff SeriesGroupBy 比较慢
- c - 分段错误后如何获取 RIP?
- c# - c#如何将int数组转换为字符串二进制数组
- ionic3 - 如何在 ionic 中嵌入 javascript 播放器?