[英]Navigation drawer is not collapsing, no hamburger button is there
My drawer layout is showing as a normal activity without any button in the toolbar also its not collapsing in any way..I want it from right side. 我的抽屉布局显示为正常活动,工具栏中没有任何按钮,也没有以任何方式折叠。.我希望从右侧开始。
This is my drawer activity layout.. 这是我的抽屉活动布局。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".myDrawer"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#000"
android:id="@+id/drawer_toolbar"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:background="@color/colorPrimaryDark"
android:layout_width="100dp"
android:layout_height="match_parent"
android:foregroundGravity="left"
app:menu="@menu/drawer_menu"
app:headerLayout="@layout/nav_header">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
this is my nav_header.xml layout. 这是我的nav_header.xml布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="300dp"
android:padding="15dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:layout_width="100dp"
android:layout_height="200dp"
android:src="@drawable/hhh"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="pehli line"
android:textColor="@color/colorPrimaryDark"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="dusri line"
android:textColor="@color/colorAccent"/>
</LinearLayout>
This is drawer activity java 这是抽屉活动java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
public class myDrawer extends AppCompatActivity {
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_drawer);
toolbar=findViewById(R.id.drawer_toolbar);
setSupportActionBar(toolbar);
}
}
Output of above code --> 上面代码的输出 ->
but I want it a navigation drawer, that i can slide from left. 但我想要一个导航抽屉,以便我可以从左侧滑动。 Thank you so much. 非常感谢。
Replace your navigation view with below 将导航视图替换为以下内容
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/my_menu">
</android.support.design.widget.NavigationView>
Add below method to display toggel 添加以下方法以显示toggel
public void addToggel() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
//drawer.setDrawerListener(toggle);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
}
Add below string in string.xml 在string.xml中的字符串下方添加
<string name="navigation_drawer_open">open</string>
<string name="navigation_drawer_close">close</string>
update drawer layout id and navigation view id as per your code 根据您的代码更新抽屉布局ID和导航视图ID
Let me know with more help 让我知道更多帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.