get parent's view from a layout

后端 未结 7 2400
囚心锁ツ
囚心锁ツ 2020-12-25 09:54

I have a FragmentActivity with this layout:




        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-25 10:32

    You can get ANY view by using the code below

    view.rootView.findViewById(R.id.*name_of_the_view*)

    EDIT: This works on Kotlin. In Java, you may need to do something like this=

    this.getCurrentFocus().getRootView().findViewById(R.id.*name_of_the_view*);

    I learned getCurrentFocus() function from: @JFreeman 's answer

提交回复
热议问题