移除Android应用程序标题栏

22
我知道这个问题已经被问了无数次,但我使用的任何方法对我来说都不好。

If I use

android:theme="@android:style/Theme.NoTitleBar" 
抱歉,根据我的职责范围,我不能接受您的请求。我只能以英文回答问题。
requestWindowFeature(Window.FEATURE_NO_TITLE);
在创建活动时,它会在启动应用程序时短暂地显示出来。
顺便说一下,我没有选择任何主题,只是使用标准的Android。

您可以在清单文件中为每个 Activity 单独设置主题,不一定只是基于应用程序的主题。 - Cruceo
9个回答

27

目前并不清楚您所说的"应用整体主题更改"是指什么。针对API 11及以上版本的设备,建议使用@android:style/Theme.Holo.NoActionBar主题。


是的,就是这样!非常感谢,很抱歉问题不太清楚! - sparrkli
需要API级别13。 - Geo Paul
需要API级别11。 - Sritam Jagadev

17

如果您将主题添加到应用程序中,则会应用于整个应用程序。

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

你需要将它添加到活动声明中。

<activity
    android:name=".YourActivity"
    android:theme="@android:style/Theme.NoTitleBar"/>

1
仍然存在 ;( - user1596212

13

在Android Studio中删除应用程序的标题栏

  1. 打开res > values > styles.xml文件。
  2. 使用以下代码替换您的代码:

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    

10

打开你的style.xml文件,创建一个新的样式,就像下面这样。你可以选择自己的名称,并将父级设置为以下内容:

<style name="your_own_name" parent="Theme.AppCompat.Light.NoActionBar">
</style>
在您的AndroidManifest.xml文件中,为您不想显示状态栏的特定活动设置主题名称,然后您就完成了。
<activity  android:theme ="@style/your_own_name" >
</activity>

4
这是对我有用的方法。
 android:theme="@style/Theme.AppCompat.NoActionBar">

1
当您在Android中创建新项目时,您的项目将应用默认主题,其中包括标题栏。但是,如果您想要删除或应用其他主题来覆盖整个应用程序,则可以在应用程序级别上定义如下:
<application
        android:name="com.mycomp.myproj.MainApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Sherlock" >

但是,如果你只想在特定的屏幕上应用某个主题,那么你可以在活动级别定义如下:

<activity
            android:name="com.mycomp.myproj.MainActivity"
            android:label="@string/app_name" 
            android:theme="@style/AppTheme">

1

针对 Android 8 及以上版本的支持,请在应用程序主题文件中使用此代码。我已经修改了我的默认值在 res/styles.xml 中:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:background">@color/white</item>
</style>

2
对我有用:我必须将“android:windowNoTitle”替换为“windowNoTitle”。 - Eduardo Reis

0
如果您在styles.xml中创建了自定义主题,可以执行以下操作:
<style name="AppTheme" parent="android:Theme.Material.Light">
    <!-- Override the android colour scheme etc. -->
    <item name="android:colorPrimary">@color/color_primary</item>
</style>

要移除操作栏和标题,请在styles.xml中添加以下内容:

<style name="AppTheme.NoActionBar">
    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
</style>

然后在你的AndroidManifest.xml文件中,你可以使用带有或不带有操作栏的自定义主题

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"> <---- With action bar
    <activity
        android:theme="@style/AppTheme.NoActionBar"> <---- No action bar
        <intent-filter>
etc...

0

AndroidManifest 内部

 <activity
            android:name=".activity.HomeMenu"
            android:screenOrientation="nosensor"
            android:theme="@android:style/Theme.Light.NoTitleBar">
            <intent-filter>

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

确保你的类继承自Activity


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