androidx.appcompat.app.ActionBarDrawerToggle中不显示导航按钮(汉堡包)按钮

时间:2019-07-08 13:44:10

标签: android androidx navigation-drawer

在清单xml中

<application
            android:name=".main.MainApp"
            android:allowBackup="true"
            android:icon="@drawable/ic_app"
            android:label="@string/application_name"
            android:logo="@drawable/ic_app_logo"
android:theme="@style/MainAppBaseTheme">

样式:

    <style name="MainAppBaseTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="colorControlNormal">@android:color/white</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <!--item name="colorPrimaryDark">@color/colorPrimaryDark</item>-->
        <item name="colorAccent">@color/colorAccent</item>
</style>

这里是我的布局,用于显示导航抽屉

<androidx.drawerlayout.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolBar"
                android:layout_width="match_parent"
                android:layout_height="@dimen/tool_bar_height"/>


    </LinearLayout>

    <!-- Framelayout to display Fragments -->
    <FrameLayout
            android:id="@+id/frame_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    </FrameLayout>

    <!-- Listview to display slider menu -->

    <ListView
            android:id="@+id/list_slidermenu"
            android:layout_width="288dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@color/list_background"
            android:choiceMode="singleChoice"
            android:divider="@null"
            android:listSelector="@drawable/list_selector"
            android:paddingLeft="16dip"
            android:paddingRight="16dip"/>

</androidx.drawerlayout.widget.DrawerLayout>

此处将工具栏绑定到 ActionBarDrawerToggle

的actvitity
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.widget.Toolbar;

public class MainFragmentActivity extends FragmentActivity

 mToolbar = (Toolbar) findViewById(R.id.toolBar);
        actionBarDrawerToggle = new ActionBarDrawerToggle(
                this,
                mDrawerLayout,
                mToolbar, R.string.application_name,
                R.string.application_name) {
            public void onDrawerClosed(View view) {
                mToolbar.setTitle(mTitle);
                invalidateOptionsMenu();
}

@Override
    protected void onPostCreate(Bundle savedInstanceState) {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "onPostCreate");
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        actionBarDrawerToggle.syncState();
    }

以下是导航抽屉关闭时的结果: enter image description here

以及打开导航抽屉时

enter image description here

为什么不显示汉堡按钮?

0 个答案:

没有答案