How to set text to view from drawer header layout in navigation drawer without inflating view

后端 未结 1 1062
忘掉有多难
忘掉有多难 2020-11-27 17:09

I want to set text to the navigation drawers headers text, I searched a lot but everyone does it by inflating a layout but for me it creates 2 headers so is there any way to

相关标签:
1条回答
  • 2020-11-27 17:26

    You get navigation header view by navigationView.getHeaderView(0) , try code below

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    View header=navigationView.getHeaderView(0);
    /*View view=navigationView.inflateHeaderView(R.layout.nav_header_main);*/
    name = (TextView)header.findViewById(R.id.username);
    email = (TextView)header.findViewById(R.id.email);
    name.setText(personName);
    email.setText(personEmail);
    
    0 讨论(0)
提交回复
热议问题