在安卓系统中,是否可以让两个视图同时拥有焦点?

3
我有一个EditText和一个弹出窗口(其中包含一个ListView),现在我点击EditText,弹出窗口就会显示。
我需要的情况是:我可以在SoftInput中输入一些内容,并且我也可以单击PopupWindow的子项ListView。
现在,在Android 4.1、4.2中,我只能输入或者只能单击ListView,不能两者兼顾。但是在Android 4.4、5.0中,我可以同时进行两个操作。
我尝试了很多方法,比如popupWindo.setFocus(true),但这只会使EditText失去焦点。
所以,Android是否允许两个视图都拥有焦点?

2
没有两个视图可以同时拥有焦点。 - W I Z A R D
2个回答

4
不,两个或多个视图不能同时拥有焦点,这是不可能的。
这里,展示了如何从一个textView更改到另一个textView。你可以在你的情况下进行更改。

你的解决方案对我不起作用,我需要它们都有焦点。现在,我正在计划其他方法。我觉得可能是因为editText无法与popupWindow和ListView良好地配合,也许我可以将ListView更改为动态LinearLayout。我正在尝试。 - songzhw
没有办法让两个视图同时拥有焦点!你可以将其比作用鼠标同时点击两个按钮。 - eeffoc

3
实际上,从技术角度讲,两个视图可以同时拥有焦点 - 不仅仅是你想象的那样(也是你在使用情况下所需要的):
一个具有焦点的视图的父级视图也可以将其焦点设置为true。例如,从一个示例视图层次结构中摘录出来的内容,has-focus=true不止一次地弹出。
View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=1920, height=1080, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, 
|
+->LinearLayout{id=-1, visibility=VISIBLE, width=1776, height=1080, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=fal
|
+-->ViewStub{id=16909243, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-f
|
+-->FrameLayout{id=-1, visibility=VISIBLE, width=1776, height=1008, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=fal
|
+--->FitWindowsLinearLayout{id=2131296268, res-name=action_bar_root, visibility=VISIBLE, width=1776, height=1008, has-focus=true, has-focusable
|
+---->ViewStubCompat{id=2131296279, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, ha
|
+---->ContentFrameLayout{id=16908290, res-name=content, visibility=VISIBLE, width=1776, height=1008, has-focus=true, has-focusable=true, has-wi
|
+----->LinearLayout{id=-1, visibility=VISIBLE, width=1776, height=1008, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable
|
+------>RecyclerView{id=2131296483, res-name=lstRecordings, visibility=VISIBLE, width=1776, height=873, has-focus=true, has-focusable=true, has

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接