我正在尝试禁用某些活动的操作栏,但无论我尝试什么,我似乎无法删除它。
在我的styles.xml中,我有:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
在我的manifest.xml中,我有:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".NewActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
</activity>
</application>
我的活动布局文件:
<?xml version="1.0" encoding="utf-8"?>
<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_new"
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_main_drawer" />
</android.support.v4.widget.DrawerLayout>
我的app_bar_new布局文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="net.binarysea.sensorload.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_new" />
</android.support.design.widget.CoordinatorLayout>
我希望操作栏显示除一个(NewActivity)之外的活动。我使用Intent调用NewActivity,此时我认为它会加载AppTheme.NoActionBar样式,但栏仍然出现在屏幕上
我正在使用android studio中的导航抽屉活动,如果这会产生影响
编辑:我已尝试添加添加Theme.AppCompat.Light.NoActionBar
的所有建议,但这只会使我的操作栏变白并且实际上不会删除它。我在一个新的android工作室项目中测试了这个,创建了一个导航抽屉活动,并将主题设置添加到我的styles.xml中。我仍然遇到同样的问题
答案 0 :(得分:7)
试试这个......
只需为您的样式添加父标记即可。
<强> Styles.xml 强>
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<强>的AndroidManifest.xml 强>
.......
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".NewActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
</activity>
</application>
........
答案 1 :(得分:2)
尝试将以下内容放入清单中
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
答案 2 :(得分:0)
在styles.xml
中使用这样的方法#
# AmiModRadio
# All of Aminet modules at your fingertips
#
#
#
# Copyright 2015, 2016 Tygre <tygre@chingu.asia>
#
# This file is part of AmiModRadio.
#
# AmiModRadio is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# AmiModRadio is distributed in the hope fthat it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with AmiModRadio. If not, see <http://www.gnu.org/licenses/>.
#
#
#
# Entirely developed on an Amiga!
# (Except for source code versioning...)
# tygre@chingu.asia
#
# Main paths
EXEDIR = bin/vbcc-classic/debug/
OBJECTSDIR = o/vbcc-classic/debug/
# Main paths for release ONLY
ifeq "$(strip $(filter dist, $(MAKECMDGOALS)))" "dist"
EXEDIR = bin/vbcc-classic/AmiModRadio/
OBJECTSDIR = o/vbcc-classic/release/
endif
# Secondary paths
EXE = $(EXEDIR)AmiModRadio
DATADIR = $(EXEDIR)data/
ICONSDIR = $(EXEDIR)icons/
IMAGESDIR = $(EXEDIR)images/
MODULESDIR = $(EXEDIR)modules/
# (Re)Source files
SOURCES = $(wildcard *.c)
OBJECTS = $(addprefix $(OBJECTSDIR), $(SOURCES:.c=.o))
DATA = $(addprefix $(DATADIR), $(shell find data/ -mindepth 1 -maxdepth 1 -printf "%f\n" | sed 's/ /?/g'))
ICONS = $(addprefix $(ICONSDIR), $(shell find icons/ -mindepth 1 -maxdepth 1 -printf "%f\n" | sed 's/ /?/g'))
IMAGES = $(addprefix $(IMAGESDIR), $(shell find images/ -mindepth 1 -maxdepth 1 -printf "%f\n" -type d | sed 's/ /?/g'))
# compiler and linker
CC = vbcc:bin/vc
LD = vbcc:bin/vc
# Because Make does not support spaces properly...
space :=
space +=
replaceQuestionBySpace = $(subst ?,$(space),$1)
replaceSpaceByQuestion = $(subst $(space),?,$1)
# ----------------------------------------
# target 'all' (default target, for debug)
all : CFLAGS += -DFORTIFY
all : $(EXEDIR)\
$(OBJECTSDIR)\
$(EXE)\
data\
images
# target 'dist' for release
dist : mostlyclean\
$(EXEDIR)\
$(OBJECTSDIR)\
$(EXE)\
data\
icons\
images\
modules\
$(EXEDIR:/=).lha
# target 'mostlyclean'
mostlyclean :
-rm $(EXE)
-rm $(OBJECTSDIR)*
# target 'clean'
clean : mostlyclean
-rm $(DATADIR)*
-rm $(ICONSDIR)*
-rm $(IMAGESDIR)*
-rm $(MODULESDIR)*
# ----------------------------------------
# Directories
$(EXEDIR) :
mkdir "$@"
$(OBJECTSDIR) :
mkdir "$@"
# Objects and executable
$(OBJECTS) : $(OBJECTSDIR)%.o : %.c
$(CC) $(shell vbccprefs) $(CFLAGS) -c $< -o $@
$(EXE) : $(OBJECTS)
$(LD) $(shell vbccprefs) -o $(EXE) $(OBJECTS)
# Data
data : $(DATADIR)\
$(DATA)\
$(DATADIR) :
mkdir "$@"
$(DATA) : $(DATADIR)% : $(wildcard data/%)
cp -f -R "$(call replaceQuestionBySpace,data/$*)" "$(call replaceQuestionBySpace,$@)"
# Icons
icons : $(ICONSDIR)\
$(ICONS)\
$(EXE).info\
$(EXEDIR:/=).info
$(ICONSDIR) :
mkdir "$@"
$(ICONS) : $(ICONSDIR)% : $(wildcard icons/%)
cp -f -R "$(call replaceQuestionBySpace,icons/$*)" "$(call replaceQuestionBySpace,$@)"
$(EXE).info :
cp -f -R "$(ICONSDIR)AmiModRadio2.tool.info" "$@"
$(EXEDIR:/=).info :
cp -f -R "$(ICONSDIR)AmiModRadio3.drawer.info" "$@"
# Images
images : $(IMAGESDIR)\
$(IMAGES)\
$(IMAGESDIR) :
mkdir "$@"
$(IMAGES) : $(IMAGESDIR)% : $(wildcard images/%)
cp -f -R "$(call replaceQuestionBySpace,images/$*)" "$(call replaceQuestionBySpace,$@)"
# Modules
modules : $(MODULESDIR)
$(MODULESDIR) :
mkdir "$@"
# LHA archive of 'dist'
$(EXEDIR:/=).lha : PARENTDIR = $(dir $(patsubst %/,%,$(EXEDIR)))
$(EXEDIR:/=).lha : EXENAME = $(notdir $(patsubst %/,%,$(EXEDIR)))
$(EXEDIR:/=).lha :
rm -f RAM:$(EXENAME).lha
/C/LHA -r -e a RAM:$(EXENAME).lha $(PARENTDIR) $(EXENAME).info $(EXENAME)/*
为工具栏创建单独的布局
toolbar.xml
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/drawer_bg</item>
</style>
在任何活动中,使用以下代码访问此工具栏。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar 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="wrap_content" >
</android.support.v7.widget.Toolbar>
在setContentView()之后的onCreate()中使用此
Toolbar toolbar; //declaration
答案 3 :(得分:0)
您可以在NewActivity的onCreate()中尝试此操作,以隐藏特定活动的操作栏
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
答案 4 :(得分:0)
点击此链接 - https://developer.android.com/training/system-ui/status
在 Android 4.1 和更高版本的 Kotlin 上隐藏状态栏
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
supportActionBar?.hide()
最好在 onResume() 中使用它。