Is there any way to control views inside NavigationView header?

后端 未结 4 2320
我在风中等你
我在风中等你 2020-12-03 03:07

As the title says, I want to know if there is any way to control views inside the NavigationView header? (Except for adding or removing header.)

For exa

4条回答
  •  被撕碎了的回忆
    2020-12-03 03:43

    The other way to make this is using the method "inflateHeaderView()" of NavigationView object, like below (After using "setContentView()"):

    View headerLayout = navigationView.inflateHeaderView(R.layout.yours_nav_header_layout);
    

    After this point you can use "headerLayout" to access custom views in your header layout, like below:

    View cutomView = (TextView) headerLayout.findViewById(R.id.lay_sign_in);
    

    In my case i'm using ButterKnife framework to inject View "navigationView" like this:

    @Bind(R.id.nav_view) NavigationView navigationView;
    
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            ButterKnife.bind(this);
        }
    

提交回复
热议问题