How to get Activity's content view?

前端 未结 8 770
一向
一向 2020-11-27 09:22

What method should I call to know if an Activity has its contentView (once the method setContentView() has been called)?

8条回答
  •  半阙折子戏
    2020-11-27 10:14

    The best option I found and the less intrusive, is to set a tag param in your xml, like

    PHONE XML LAYOUT

    
    

    TABLET XML LAYOUT

    
    
        ...
    
    
    

    and then call this in your activity class:

    View viewPager = findViewById(R.id.pager);
    Log.d(getClass().getSimpleName(), String.valueOf(viewPager.getTag()));
    

    Hope it works for u.

提交回复
热议问题