Can't find Toolbar in an included layout

后端 未结 1 1610
南方客
南方客 2020-12-04 03:23

I have a Toolbar which has a custom TextView inside:




        
相关标签:
1条回答
  • 2020-12-04 03:52

    You are overriding the id of toolbar in the include tag. So the R.id.toolbar is no longer id of your included toolbar for your activity but now it is R.id.app_bar instead.

    If you keep the id in include tag then use following code to access your toolbar:

    Toolbar toolbar = (Toolbar) activity.findViewById(R.id.app_bar);
    
    0 讨论(0)
提交回复
热议问题