【问题标题】:Remove Navigation Drawer and want to show action bar home button instead of Navigation Drawer删除 Navigation Drawer 并希望显示操作栏主页按钮而不是 Navigation Drawer
【发布时间】:2016-02-16 13:00:57
【问题描述】:

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

显示插入符号 -> 像这样

主页视图看起来像

see here for details

fragment 视图如下所示:

see here for details Navigation drawer menu items selection snapshot

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

我怎样才能在我的应用中实现这个逻辑?

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

【问题讨论】:

标签: android android-fragments navigation-drawer


【解决方案1】:

要启用主页返回按钮,请使用以下代码。

 getSupportActionBar().setDisplayHomeAsUpEnabled(true);

【讨论】:

  • 我检查了这个片段是否正常工作,但问题是其他片段有导航抽屉菜单以及如何处理所有片段?
【解决方案2】:

通过这个创建自定义工具栏:

<?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替换你的父活动

【讨论】:

    【解决方案3】:

    在片段 onCreateView 或 onResume ((AppCompatActivity) getActivity()).getSupportActionBar().setHomeAsUpIndicator(null); 中使用它会隐藏汉堡包并显示返回按钮

    【讨论】:

      猜你喜欢
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多