我确实已将导航抽屉图标放置在操作栏上,它肯定会显示出来,但是单击抽屉图标后,该功能并没有发生,只有在滑动导航抽屉时才打开。
ArticleActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_article);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
mProgressView = findViewById(R.id.progress);
mFullContainerView = findViewById(R.id.full_container);
ActionBar actionBar = getActionBar();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
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.addDrawerListener(toggle);
toggle.syncState();
activity_article.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
<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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:focusableInTouchMode="true"
android:scrollbars="vertical"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_article_drawer" />
<include layout="@layout/list_view" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
答案 0 :(得分:0)
在您的代码中,您好像将自定义工具栏用作操作栏,但是尚未将其设置为支持操作栏。您需要使用setSupportActionBar(toolbar)
将自定义工具栏设置为操作栏。
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
此外,请确保从没有动作栏的主题扩展应用程序主主题。