Can two views both have focus in Android

前端 未结 2 1296
灰色年华
灰色年华 2021-01-20 17:43

I have a EditText, and a popupWindown(which has a ListView in it), now i touch the EditText, the popupWindow shows.

i need the situation: i can input something in

相关标签:
2条回答
  • 2021-01-20 18:12

    Actually, technically speaking two views can have focus at the same time - not just as you would imagine (and as you would need for your usecase):

    The parents of a focused view can also have their focus set to true. Cf. an excerpt from an example view hierarchy, has-focus=true pops out more than once:

    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
    
    0 讨论(0)
  • 2021-01-20 18:14

    No, two (or more) views cannot have focus at the same time, not possible.

    Here is how to change focus from one textView to another textView. Which you could change in your case.

    0 讨论(0)
提交回复
热议问题