abh*_*zag 1 android accessibility
我试图确保键盘导航在我的应用程序上正常工作,并且当用户点击“Tab”键或“向上/向下”箭头键时,所有视图元素都可以聚焦。但是, AppBarLayout 似乎捕获了键盘焦点。我在配置了键盘的模拟器上运行我的应用程序。示例布局如下:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/search_fragment_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical"
android:scrollbars="horizontal"
android:focusable="true"
android:nextFocusDown="@id/recycler_view">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Sample text 1"
android:focusable="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Sample text 2"
android:focusable="true"/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:focusable="true"
app:layout_constraintTop_toBottomOf="@layout/content_main"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
点击 Tab 键或向上/向下箭头不会将焦点切换到回收器视图,并且焦点停留在 AppBarLayout 内。在 textviews 上设置 nextFocusDown 属性并将视图元素设置为保持可聚焦也不起作用。这是图像。我需要做什么才能使此布局可访问?
小智 6
我想你需要打电话
findViewById(R.id.search_fragment_app_bar).setTouchscreenBlocksFocus(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
findViewById(R.id.search_fragment_app_bar).setKeyboardNavigationCluster(false);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
412 次 |
| 最近记录: |