在NavigationView上能不能全人物召唤系统Dialog?

NavigationView相关问题【androidstudio吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:10,552贴子:
NavigationView怎么没有android:layout_gravity=&start&属性提示
急啊急啊,有人知道吗
登录百度帐号个回答以下是我如何解决这个问题,并且完美地工作:&android.support.design.widget.NavigationView
android:id=&@+id/navigation&
android:layout_width=&wrap_content&
android:layout_height=&match_parent&
android:layout_gravity=&start&
android:fitsSystemWindows=&true&&
&LinearLayout
android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:orientation=&vertical&&
&include layout=&@layout/nav_header& /&
android:id=&@+id/lst_menu_items&
android:layout_width=&match_parent&
android:layout_height=&0dp&
android:layout_weight=&1& /&
&/LinearLayout&
&/android.support.design.widget.NavigationView&
只需在NavigationView中进行自定义布局即可:&android.support.v4.widget.DrawerLayout
android:id=&@+id/drawer&
xmlns:android=&http://schemas.android.com/apk/res/android&
xmlns:app=&http://schemas.android.com/apk/res-auto&
android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:fitsSystemWindows=&true&&
&android.support.design.widget.NavigationView
android:id=&@+id/navView&
android:layout_width=&wrap_content&
android:layout_height=&match_parent&
android:layout_gravity=&start&&
android:entries=&@array/test&
android:layout_width=&match_parent&
android:layout_height=&match_parent&/&
&/android.support.design.widget.NavigationView&
&/android.support.v4.widget.DrawerLayout&
扫描二维码扫描关注云+社区1.3k 次阅读
前几天把Android官方的Design包从23.0.1升级到23.1.1,结果万万没想到,官方给的Design包居然“出问题了”,之前在headerLayout中写的布局文件findviewById后,找不到,会报错。
后来,Google了一下,发现不少人都碰到这个错误,先说解决办法,有两种
第一个,憋升级,还是先退回去吧,继续23.0.1的Design包用着。
第二个,先得到headerLayout的父级容器,再用它的父级容器去findviewById,下边是示例代码
headerView = navigationView.getHeaderView(0);
userName = (TextView) headerView.findViewById(R.id.user_name);
搞不懂Google官方推荐的东西,为什么升级的时候还会出现这种问题。
原文地址:转载请注明出处!
0 收藏&&|&&1
分享到微博?
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。安卓中navigationview怎么和fragment一起使用_百度知道
安卓中navigationview怎么和fragment一起使用
答题抽奖
首次认真答题后
即可获得3次抽奖机会,100%中奖。
使用方式:第一步:新建项目FragmentStudy,AndroidManifest.xml如下:&?xml version=&1.0& encoding=&utf-8&?&&manifest xmlns:android=&&package=&com.example.fragmentstudy&android:versionCode=&1&android:versionName=&1.0& &&uses-sdkandroid:minSdkVersion=&8&android:targetSdkVersion=&17& /&&applicationandroid:allowBackup=&true&android:icon=&@drawable/ic_launcher&android:label=&@string/app_name&android:theme=&@android:style/Theme.Black.NoTitleBar& &&activityandroid:name=&com.example.fragmentstudy.MainActivity&android:label=&@string/app_name& &&intent-filter&&action android:name=&android.intent.action.MAIN& /&&category android:name=&android.intent.category.LAUNCHER& /&&/intent-filter&&/activity&&/application&&/manifest&第二步:创建ExampleFragment(Fragment的子类)与ExampleFragment相应的布局文件layout_fragment_example.xml。 【layout_fragment_example.xml】&?xml version=&1.0& encoding=&utf-8&?&&LinearLayout xmlns:android=&&android:layout_width=&match_parent&android:layout_height=&match_parent&android:orientation=&vertical& &&TextView android:layout_height=&wrap_content&android:layout_width=&match_parent&android:text=&ExampleFragment&android:gravity=&center&android:id=&@+id/fragment_textView&android:textColor=&@android:color/black&/&&/LinearLayout&【ExampleFragment.java】import java.util.D
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
如图标注区域中的View怎么实现点击事件?
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
建议另一个实现方式,不过思路也和采纳答案的类似:
先在Activity中声明NavigationView,然后再通过View view = NavigationView.inflateHeaderView(int LayoutResID)这个方法导入头部布局文件,这就意味着在NavigationView中不会静态去设置app:header属性,并且获取了头部的View,这样就可以通过View.findId...()方法来定位和监听了。
另外头部的监听事件是可以写在Activity里面的,跟其他Activity布局里的控件的监听事件写在一起是木有问题的。
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
我已经解决,先获得头部的View,再findViewByid();
代码如下:
headerView = navigationView.getHeaderView(0);
headImg = (ImageButton)headerView.findViewById(R.id.user_head_img);
userName = (TextView) headerView.findViewById(R.id.user_name);
userDescription = (TextView) headerView.findViewById(R.id.user_description);
可能之前的Support Design包可以直接findViewById();我接触安卓开发比较晚晚,不太清楚,我现在用的是'com.android.support:design:23.1.1',这个用这种方式即可。
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
难道不能findviewById点击吗?
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
请问监听事件写在什么地方。。。怎么我写在别的地方都会报null
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
直接findviewby获取,就行了啊!!!直接findviewby获取,就行了啊!!!直接findviewby获取,就行了啊!!!例行三遍
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
你如果在oncreate里findview肯定是不行的,找到这个控件的父容器,比如root这个是navi的ViewGroup,然后调用navi的findviewbyid
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
这个header也是个layout啊
findviewbyid就ok
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
很有用,谢谢
同步到新浪微博
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。

我要回帖

更多关于 召唤与合成 的文章

 

随机推荐