Android Api 23 Change Navigation View headerLayout textview

こ雲淡風輕ζ 提交于 2019-11-27 07:04:45
orium

I had the same issue and was able to avoid it with this code:

    View header = LayoutInflater.from(this).inflate(R.layout.nav_header_main, null);
    navigationView.addHeaderView(header);
    TextView text = (TextView) header.findViewById(R.id.textView);
    text.setText("HELLO");

Now with the 23.1.1 release of the design support library, you can use

View header = navigationView.getHeaderView(0)
TextView text = (TextView) header.findViewById(R.id.textView);

Orium answer works and this will work as well.

View header = navigationView.inflateHeaderView(R.layout.nav_header_main);
    TextView text = (TextView) header.findViewById(R.id.textView);
    texto.setText("HELLO");

this solved the problem for me

    View headerView = navigationView.inflateHeaderView(R.layout.header_view);

    txt_fullname = (TextView) headerView.findViewById(R.id.txt_fullname);
    txt_email = (TextView) headerView.findViewById(R.id.txt_email);
View headerView=navigationView.getChildAt(0);
TextView tvName=(TextView)hView.findViewById(R.id.name);
TextView tvEmail=(TextView)hView.findViewById(R.id.email);

    tvName.setText(data);
    tvEmail.setText(data);

Or if you use this attribute:

<android.support.desibn.widget.NavigationView>
    ...
    app:headerLayout="@layout/your_header_layout"/>

You can:

View header = mNavigationView.getHeaderView(0);
TextView title = (TextView) header.findViewById(R.id.your_title_id);
//Or something else
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!