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

前端 未结 16 845
半阙折子戏
半阙折子戏 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:26

    don't add header in xml add using code by inflating layout

    View hView =  navigationView.inflateHeaderView(R.layout.nav_header_main);
    ImageView imgvw = (ImageView)hView.findViewById(R.id.imageView);
    TextView tv = (TextView)hView.findViewById(R.id.textview);
    imgvw .setImageResource();
    tv.settext("new text");
    

提交回复
热议问题