问题描述
我试过navigationView从全新的Android支持设计库。我想有一个动态的headerview。基本上,我headerview会显示类似的每日新闻。我有一个10左右的报价,我想随机选择一个报价,并显示在headerView一个TextView。我也想添加的onClick方法的headerView。
I tried the navigationView from the new android support design library. I want to have a dynamic headerview. Basically, my headerview will show something like quote of the day. I have like around 10 quotes and i want to randomly select a quote and display in a textview in the headerView. I also want to add onClick method for the headerView.
现在,我看不出编程改变headerview布局的任何可能性。任何建议,以实现这一点?
Right now, I don't see any possibilities of changing the headerview layout programmatically. Any suggestions to implement this?
推荐答案
首先创建一个类似头的XML lay_header.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...
这篇关于定制NavigationView - 添加动态headerView,支持Android设计库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!