标签:android category ras div tty support itemid layout sed
版权声明:本文为博主原创文章,未经博主允许不得转载。
本文地址:http://blog.csdn.net/u011181236/article/details/51985242
1.布局要注意的就是
Android:layout_gravity=”right”
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
2.Java代码
这个是设置toolbar里左上角menu按钮的点击事件
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!drawer.isDrawerOpen(setDrawerGravity())) {
drawer.openDrawer(setDrawerGravity());
}
}
});
3.这里只有4个属性可用
Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right.GravityCompat.START or GravityCompat.END may also be used.
private int setDrawerGravity() {
return Gravity.RIGHT;
}
4.返回键处理
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(setDrawerGravity())) {
drawer.closeDrawer(setDrawerGravity());
} else {
super.onBackPressed();
}
}
5.NavigationView 的item点击处理
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener(){
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(setDrawerGravity());
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
}
return true;
}
});
1
(转载) 使用DrawerLayout和NavigationView从右侧出现
标签:android category ras div tty support itemid layout sed
原文地址:http://www.cnblogs.com/liupengfei005257/p/7447149.html