0

When I press any key on my hardware keyboard hamburger icon took focus: enter image description here

How I can prevent this?

UPDATED:

I have a fragment with toolbar:

<RelativeLayout 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">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:layout_gravity="center"
        android:gravity="center">

        <ImageView
            android:id="@+id/toolbarLogo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"/>

        <TextView
            android:id="@+id/toolbarTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"/>

        <ImageView
            android:id="@+id/toolbarTitleMenu"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:paddingEnd="16dp"
            android:paddingStart="16dp"/>

    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</RelativeLayout>

It looks like hamburger view is the first focusable view. If I add empty view with focusable=true before AppBarLayout then it prevent. But, is there more elegant solution?

Alexey Nikitin
  • 604
  • 7
  • 22

1 Answers1

0

I added empty view into the first position of decorView:

val focusable = View(context)
focusable.isFocusable = true
val lp = ViewGroup.LayoutParams(1, 1)
(window.decorView as ViewGroup).addView(focusable, 0, lp)
Alexey Nikitin
  • 604
  • 7
  • 22