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

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

    As mentioned in the bug 190226, Since version 23.1.0 getting header layout view with: navigationView.findViewById(R.id.navigation_header_text) no longer works.

    A workaround is to inflate the headerview programatically and find view by ID from the inflated header view.

    For example:

    View headerView = navigationView.inflateHeaderView(R.layout.navigation_header);
    headerView.findViewById(R.id.navigation_header_text);
    

    Ideally there should be a method getHeaderView() but it has already been proposed, let's see and wait for it to be released in the feature release of design support library.

提交回复
热议问题