How do I get the view of a Tab in a TabLayout?

前端 未结 3 780

I\'d like to find the view of a Tab in a TabLayout so that I can pass it to another function. I\'m not sure how to go about finding the view. myTabLayout.getTabAt(0).getC

3条回答
  •  -上瘾入骨i
    2021-02-09 04:00

    It returns null because you're not using any Custom View in the first place. It returns the custom view only when you use it. For using the custom view, your code should be something like this.

    tabLayout.addTab(tabLayout.newTab().setCustomView(R.layout.custom_view).setText("Page1"));
    

    If you use the above line and then try to call myTabLayout.getTabAt(0).getCustomView(), it'd return you the view that you set.

提交回复
热议问题