除主 Activity 之外的所有 Activity 中的 Android 操作栏

标签 android

我是 android 的新手,我正在尝试向我的项目添加抽屉导航(仅在一个 Activity 中)。 问题是当我添加抽屉时出现错误。为了解决这个问题,我将应用样式更改为 Theme.AppCompat.NoActionBar,但这样做会删除其他 Activity 中的所有其他操作栏。

如果可以解决我的问题,我想在项目中使用另一种样式并仅在该主要 Activity 中删除操作栏。 希望你们能帮助我。谢谢。

这是我的代码:

<style name="MyAppStyle" parent="@style/Theme.AppCompat.NoActionBar"> <item name="colorPrimary">@color/bg_login</item> <item name="colorPrimaryDark">@color/bg_login</item> <item name="colorAccent">@color/activity_background</item> </style>

java代码:

private void setDrawer(){
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    android.support.v7.app.ActionBarDrawerToggle toggle = new android.support.v7.app.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);
    navigationView.setNavigationItemSelectedListener(this);
}

xml文件:

<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"
tools:openDrawer="start" >

<include
    layout="@layout/app_bar_main"
    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:background="@color/bg_login"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

最佳答案

<activity
           android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    />

只需将您的主题设置为仅适用于 mainactivity 的主题,然后它就不会在该特定 Activity 上显示 actionbar

关于除主 Activity 之外的所有 Activity 中的 Android 操作栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36796226/

相关文章:

Android 相机 API ISO 设置?

android - 每次我构建我的 Android 应用程序(在手机上运行)时,我都会丢失磁盘空间

android - DocumentSnapshot (Firestore) 到包含自定义对象列表的 Kotlin 对象

android - 如何在 Android 4.4 中查找数据库路径(API 级别 : 19)?

java - android.view.InflateException 错误膨胀类 com.etsy.android.grid.StaggeredGridView

Micromax funbook 平板电脑的安卓开发

java - Google Play 'Open Testing'(= 抢先体验): 'Release not live' error message

android - 如何在 Android 中获取片上系统信息(Samsung Exynos、Nvidia Tegra 等)?

android - python android 脚本在 AVD 设备中崩溃

每行具有不同布局的Android ListView