删除导航抽屉,并希望显示操作栏主页按钮而不是导航抽屉

时间:2016-02-16 13:00:57

标签: android android-fragments navigation-drawer

主页应该有导航抽屉其他页面没有导航抽屉

显示插入符号 - >像这样

主页视图看起来像

see here for details

fragment视图如下所示:

see here for details Navigation drawer menu items selection snapshot

使用navigation drawer开发应用程序我的主页上有导航抽屉我希望隐藏导航抽屉并显示操作栏主页按钮setHomeAsUpEnabled = true而不是导航抽屉。

如何在我的应用程序中实现此逻辑?

如果有人知道这件事,请告诉我吗?

3 个答案:

答案 0 :(得分:0)

启用Home back按钮使用以下代码。

 getSupportActionBar().setDisplayHomeAsUpEnabled(true);

答案 1 :(得分:0)

通过以下方式创建客户工具栏:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="@mipmap/top_bar_bg"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    />

把它放在活动中

private Toolbar toolbar;
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);            getSupportActionBar().setDisplayHomeAsUpEnabled(true);

把它放在清单

<activity
            android:name=".activity.RegisterActivity"
            android:label="@string/profile"
            android:parentActivityName=".activity.HomeActivity"
            >

将您当前的活动替换为android:name和 用android:parentActivity

替换您的父活动

答案 2 :(得分:0)

将其用于片段onCreateView或onResume ((AppCompatActivity) getActivity()).getSupportActionBar().setHomeAsUpIndicator(null);中,这些片段将隐藏汉堡包并显示后退按钮