NavigationView侧滑导航布局
2023-01-24 09:16:15 最后更新
NavigationView在MD里很常用,起了指导用户功能的作用,MD文档说“电脑端也可经常用”
代码:
//构造控件
javanew(nv,"android.support.design.widget.NavigationView","android.content.Context",activity)
//放入实例中,did最好在侧滑的布局里
nvw(nv,did)
us(nv,"height",-1)
//暂时做不到点击菜单缩回侧滑的,在菜单事件里用吧
//准备Menu
java(menu,nv,"android.support.design.widget.NavigationView.getMenu")
//如果你用了彩色图标,请用下面方法
//如果你设置了人头像作图像,那你会有灰人效果(笑)
//java(null,nv,"android.support.design.widget.NavigationView.setItemIconTintList","android.content.res.ColorStateList",null)
//这里用之前我发的菜单控制
......
//下面如果你需要头控件(跟随菜单一起滚动的),比如用户登录,用下面代码
//引用了扛把子代码
//设置头控件
javanew(布局参数,"android.widget.LinearLayout$LayoutParams","int",-1,"int",-2)
javanew(线性布局,"android.widget.LinearLayout","Context",activity)
java(null,线性布局,"android.view.View.setLayoutParams","android.view.ViewGroup$LayoutParams",布局参数)
java(null,线性布局,"android.widget.LinearLayout.setOrientation","int",1)
//下面参数是你的头控件的界面文件
addv(线性布局,"界面名")
java(null,nv,"android.support.design.widget.NavigationView.addHeaderView","android.view.View",线性布局)
.作者:MC的wither菌