简体   繁体   English

Android ActionBar和蓝牙键盘

[英]Android ActionBar and Bluetooth keyboard

My android application uses a bluetooth pedal for hands free navigation. 我的Android应用程序使用蓝牙踏板进行免提导航。 The pedal - an AirTurn BT105 - registers itself as a hardware keyboard. 踏板-AirTurn BT105-将其自身注册为硬件键盘。

I can capture the keys sent by the pedal in my activity via dispatchKeyEvent(KeyEvent event) , and everything works OK. 我可以通过dispatchKeyEvent(KeyEvent event)捕获活动中踏板发送的按键,一切正常。

However, even though I return true when I intercept the key, the actionbar is also responding to the key event. 但是,即使我在截获按键时返回true,操作栏也将响应按键事件。 In my ActionBar , I have a series of ImageView s for specialised layout purposes. 在我的ActionBar ,我有一系列ImageView用于专门的布局目的。 The first ImageView is getting highlighted, as if it receives just an ACTION_DOWN message. 第一个ImageView突出显示,好像它仅收到ACTION_DOWN消息一样。 In addition, although the layout file specifies that the ImageView should not receive focus, when I look at it through the view hierarchy viewer, they are all stated as being focusable. 另外,尽管布局文件指定ImageView不应该获得焦点,但是当我通过视图层次结构查看器查看它时,它们都被声明为可聚焦的。

Is there a means to stop this behaviour ? 有办法阻止这种行为吗?

Can I intercept the navigation key events for the ActionBar window as well ? 是否可以拦截ActionBar窗口的导航键事件?

Note : using native ActionBar in Android 4.4.2 注意:在Android 4.4.2中使用本机ActionBar

The solution to this "problem", was to manually set the focusable property when building the actionbar menu. 解决此“问题”的方法是在构建操作栏菜单时手动设置focusable属性。

1 - Get the actionview item with 1-使用

View v = menu.findItem(itemId).getActionView();

2 - After having done your setup and enabled or disabled it, set the focusable values 2-完成设置启用或禁用它之后,设置可聚焦的值

v.setFocusable(false);
v.setFocusableInTouchMode(false);

When enabled the user will still be able to tap / click on the widget and it will still respond. 启用后,用户仍然可以点击/单击小部件,并且仍然会响应。

I hope this helps someone, eventually 我希望这可以帮助某人,最终

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM