在我的安卓手机和平板电脑中隐藏顶部菜单栏

11

我想隐藏我的安卓设备和平板电脑的顶部菜单栏。有人可以告诉我如何进行操作吗?谢谢任何帮助。


请查看此链接:https://dev59.com/zG855IYBdhLWcg3wXS8I#4388099 - Ken Wolf
1
在AndroidManifest文件中的<activity>标签中包含android:theme="@android:style/Theme.NoTitleBar" - Paresh Mayani
1
真的吗!!!你想隐藏返回和主页按钮!!! - shreyas
是的,我想要隐藏返回和主页按钮。 - joe
我想隐藏底部栏,也就是带有主页、返回和最近应用程序按钮的栏。如何隐藏底部栏? - joe
显示剩余4条评论
8个回答

9

您可以通过在AndroidManifest.xml文件中的<application>元素上设置android:theme属性为@android:style/Theme.NoTitleBar来实现此目的,如下所示:

<activity android:name=".Activity"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

2
我尝试了这个,但是它给了我一个Gradle构建错误:"java.lang.IllegalStateException: 您需要在此活动中使用Theme.AppCompat主题(或其子类)"。 - Rock Lee
android:theme="@style/Theme.AppCompat.NoActionBar" 对我有用。 - luckyging3r

8
在Activity类中,您可以在onCreate方法中使用此功能。在api级别大于11时。
ActionBar actionBar = getActionBar();
actionBar.hide();

或者
getSupportActionBar().hide();

1
在 actionBar.hide() 这一行出现了 Null pointer 异常。 - joe
getSupportActionBar().hide(); - Muhammad Aamir Ali
没有这样的方法getSupportActionBar()。在getSupportActionBar().hide()这一行会出现错误。 - joe
我需要给我的安卓平板设备进行root吗? - joe
有人理解我的问题吗? - joe

7
为了方便搜索,当在Android Studio中创建项目时,你的AndroidManifest.xml(如@Jay所示)将引用下面所示的“AppTheme”主题:
<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
...

如果您导航到文件夹树 res/values/styles.xml,您可以将样式设置为继承自父样式。在我的情况下,这对于整个应用程序的解决方案非常有效。

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
    </style>

</resources>

如果您使用的是深色主题,可以将“.light”移除。
更多阅读内容请点击此处

2
为了隐藏选项卡底部的状态栏,您可以查看此库,我认为这将有助于您的使用情况。 HideBar Library Android。然而,此库需要一个ROOTed设备才能工作,我认为这是您在4.0.1以上版本的设备上唯一能使其正常工作的情况。
此外,对于Android版本<4,您可以尝试在设置布局之前在onCreate()方法中添加以下代码行。
WindowManager.LayoutParams attrs = getWindow().getAttributes(); 
attrs.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN; 
getWindow().setAttributes(attrs); 

如果你的应用程序 targetSdk 版本是11或以上(包括Honeycomb及其后续版本),那么你应该使用 Holo 风格。因此,在你的清单文件中,在 <application> 标签中使用以下属性:
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" 

对于安卓2.3.3及以下版本,您可以将以下内容添加到清单xml文件中的application标签中:android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"。这将使您的应用在全屏模式下运行。如果您想要有标题栏,只需创建一个自定义标题栏并将其放入所有其他活动都将继承的基本活动中即可。
希望这可以帮助您!

0
在你的styles.xml文件中添加这行代码。
<item name="android:windowNoTitle">true</item>

它基本上做的与添加相同

android:theme="@android:style/Theme.NoTitleBar"

将该行添加到您的清单文件中,但您可以通过将该行添加到styles.xml中来保留自己的自定义样式


0

添加这个

ActionBar actionBar = getActionBar();
    actionBar.hide();

0

0

不显示比显示后再隐藏更好。您可以通过在应用程序块的主AndroidManifest.xml文件中定义NoActionBar主题来禁用顶部标题ActionBar菜单的显示:

android:theme="@style/AppTheme.NoActionBar"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接