In android how to set navigation drawer header image and name programmatically in class file?

前端 未结 16 910
半阙折子戏
半阙折子戏 2020-12-04 07:53

In android studio 1.4.1, I have created new Navigation Drawer Project which is default.My issue is in this project there is nav_header_main.xml file which is for navigation

16条回答
  •  时光取名叫无心
    2020-12-04 08:31

    Here is my code below perfectly working Do not add the header in NavigationView tag in activity_main.xml

    
    
    
    

    add header programmatically with below code

    View navHeaderView = navigationView.inflateHeaderView(R.layout.nav_header_main);
        headerUserName = (TextView) navHeaderView.findViewById(R.id.nav_header_username);
        headerMobileNo = (TextView) navHeaderView.findViewById(R.id.nav_header_mobile);
        headerMobileNo.setText("+918861899697");
        headerUserName.setText("Anirudh R Huilgol");
    

提交回复
热议问题