Android-UI:使用硬件键盘/条形码扫描仪时无焦点标记

时间:2016-03-21 08:52:41

标签: android focus

目前,我正在开发一款使用条形码阅读器扫描条形码的应用。条形码阅读器被android识别为硬件键盘。这工作正常,我可以阅读条形码。但是当我读取条形码时,AppBar中的汉堡包会聚焦(见截图)。 如何摆脱焦点标记?我试图将焦点设置为另一个控件,但这并不起作用。是否可以覆盖焦点标记的样式?

屏幕截图:http://postimg.org/image/7zmzzhstx/

1 个答案:

答案 0 :(得分:1)

在再次解决这个问题之后,我找到了一个适合我的解决方案。也许这可以帮助其他人:

在我的活动中,我覆盖了公共布尔值dispatchKeyEvent(KeyEvent事件)方法来处理来自条形码扫描器的输入。我现在添加了以下代码行:

containerContent.requestFocus();

containerContent控件只是一个FrameLayout,托管我的片段。在我发布这个问题之前我已经尝试过了。但它没有用,因为FrameLayout“不允许”请求焦点。现在我修改了我的布局xml:

<FrameLayout
    android:id="@+id/containerMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true">
</FrameLayout>

添加了android:focusable="true"android:focusableInTouchMode="true",现在可以了!