AppWidgetHost 如何将焦点设置到 AppWidget 按钮?
我正在开发 Android 启动器应用程序。我可以托管 AppWidget 并将它们显示在我的视图上,该视图派生自 LinearLayout。我不知道如何将焦点设置到小部件内的按钮(例如,电源控制小部件的各个控件),就像默认启动器一样。
这就是我将焦点分配给 AppWidgetHostView 的方式:
widgetView.setFocusable(true);
widgetView.setSelected(true);
widgetView.requestFocus(true);
整个小部件都有焦点。我知道这一点是因为如果我单击 dpad Enter 按钮,整个小部件都会闪烁。
如何将焦点设置到小部件内的按钮之一?我需要枚举小部件的 RemoteViews 吗?如果是这样,怎么办?
I am working on an Android Launcher application. I can host AppWidgets and display them on my View, which is derived from a LinearLayout. I can't figure out how to set focus to the buttons within the widget (for example, the individual controls of the Power Control widget), as happens with the default launcher.
This is how I am assigning the focus to the AppWidgetHostView:
widgetView.setFocusable(true);
widgetView.setSelected(true);
widgetView.requestFocus(true);
The entire widget has the focus. I know this because the entire widget flashes if I click the dpad enter button.
How do I set the focus to one of the buttons within the widget? Do I need to enumerate the RemoteViews of the widget? If so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。 (谢谢 HierarchyViewer)。如果AppWidgetHostView的第一个子项是ViewGroup(例如LinearLayout),我会从小部件中删除焦点并使用FocusFinder将焦点分配给第一个子项。
I figured it out. (Thank you HierarchyViewer). If the AppWidgetHostView first child is a ViewGroup (e.g. LinearLayout), I remove focus from the widget and use the FocusFinder to assign focus to the first child.