两个视图都可以在Android中关注

时间:2014-12-04 08:30:32

标签: android android-edittext android-popupwindow

我有一个EditText和一个popupWindown(里面有一个ListView),现在我触摸EditText,popupWindow显示。

我需要这样的情况:我可以在SoftInput中输入内容,我也可以单击ListView中的子项,这是PopupWindow的子项。

现在,我只能输入,或者只能点击列表视图,我无法在Android 4.1,4.2中执行这两项操作。但我可以在Android 4.4,5.0中做到这两点。

我试过很多方面,比如popupWindo.setFocus(true),它只会让EditText失去焦点。

那么,android可以让两个视图都有焦点吗?

2 个答案:

答案 0 :(得分:4)

不,两个(或更多)视图不能同时具有焦点,不可能。

Here 是如何将焦点从一个textView更改为另一个textView。您可以根据自己的情况进行更改。

答案 1 :(得分:1)

实际上,从技术上讲,两个观点可以同时聚焦-不只是您想像的(以及您用例所需要的):

焦点视图的父级也可以将焦点设置为true。 cf.摘自示例视图层次结构的摘录,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