Reputation: 363
At the moment I'm developing an app which uses a barcode reader to scan barcodes. The barcode reader is recognized as hardware keyboard by android. That works fine and I can read the barcodes. But when I read a barcode the Hamburger in the AppBar gets focused (see screenshot). How can I get rid of that focus marker? I tried to set the focus to an other control but that doesn't work. Is it possible to override the style of the focus marker?
Screenshot: http://postimg.org/image/7zmzzhstx/
Upvotes: 1
Views: 308
Reputation: 363
After working on that problem again I found a solution which works fine for me. Maybe that can help somebody else:
In my activity I override the public boolean dispatchKeyEvent(KeyEvent event) method to handle the input from the barcode scanner. I added now the following line of code:
containerContent.requestFocus();
The containerContent control is just a FrameLayout where are my fragments are hosted. I tried that already before I posted this question. But it didn't work because the FrameLayout is "not allowed" to request for focus. Now I modified also my layout xml:
<FrameLayout
android:id="@+id/containerMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true">
</FrameLayout>
Added the android:focusable="true"
and android:focusableInTouchMode="true"
and now it works!
Upvotes: 1