有没有什么办法来控制视图insde NavigationView“头? [英] Are there any way to control view insde NavigationView' header?

查看:211
本文介绍了有没有什么办法来控制视图insde NavigationView“头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为标题,我想知道是否有什么办法来控制视图NavigationView头里面? (除删除/添加标题请)。

As the title, i want to know if there are any way to control view inside NavigationView header? (except for removing/adding header please).

例如:在标题中,我有用户(化身)的图像,因为默认情况下它显示一个客人的形象,但用户登录后,真正的头像将显示。那么,有没有办法做到这一点?

For example: in the header, i have an image of user (avatar), as default it display a guest image, but after user logging the real avatar will be showed. So, are there any way to do that?

非常感谢!

推荐答案

因为我不能接受一个评论作为一个答案。所以,我重新发布Moinkhan'答案在这里:

Since i can not accept a comment as an answer. So, i repost Moinkhan' answer here:

首先创建一个像lay_header.xml头XML

first create header XML like lay_header.xml

<TextView
    android:id="@+id/tvThought"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

在你的java文件中充气一个TextView这上面头。像

on your java file inflate this above header in a TextView. like

TextView headerView = (TextView) LayoutInflater.from(this).inflate(R.layout.lay_header, null);
headerView.setText("Your_thoght");

现在将其添加为HeaderView

Now add it as a HeaderView

navView = (NavigationView) findViewById(R.id.navView);
navView.addHeaderView(headerView);

完蛋了...

Thats it...

您还可以检查出来的:<一href="http://stackoverflow.com/questions/30621047/customising-navigationview-adding-dynamic-headerview-android-support-design-l/30660069#30660069">Customising NavigationView - 添加动态headerView,支持Android设计库

You can also check it out at: Customising NavigationView - Adding dynamic headerView, Android Support Design Library

非常感谢! 再次,我们需要一个功能,允许用户接受评论的答复!

Many thanks! And again, we need a function that allow user to accept a comment as answer!

这篇关于有没有什么办法来控制视图insde NavigationView“头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆