Remove app title bar android

2019-01-23 02:40发布

问题:

I know this question has been asked million times but whichever method I use is not good for me.

If I use

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

in the manifest file, the whole theme of the app changes. If I put

requestWindowFeature(Window.FEATURE_NO_TITLE);

in the onCreate activities, it shows up shortly when starting an app.

Btw I don't have any theme selected, just using standard android.

回答1:

It is unclear what you mean by "whole theme of app changes". For API Level 11+ devices, you probably should be using @android:style/Theme.Holo.NoActionBar.



回答2:

If you add the theme to the application, it applies to the whole app.

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

You have to add it to the activity declaration.

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


回答3:

To remove the title bar from your app in android studio

  1. Open res > values > styles.xml file
  2. Replace your code with:

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


回答4:

Open your style.xml file, create a new style just like below. You choose your own name and set the parent as below

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

In your AndroidManifest.xml file, set the theme name for the specific activity you dont want the bar to show and you are done

<activity  android:theme ="@style/your_own_name" >
</activity>


回答5:

This is what worked for me

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


回答6:

when you create a new project in android then you will get default theme applied on your project, that has title bar. but if you want to remove or apply some other theme for your whole App then you can define like below at application level:

<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" >

but if you want to apply some theme only at some specific screens then you can define like below at activity level:

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


回答7:

For android 8 and above support. Use this in your app theme file. I've modified my default in 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>


回答8:

Inside 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>

and make sure your Class extends to Activity



回答9:

If you have made a custom theme in styles.xml you can do this:

<style name="AppTheme" parent="android:Theme.Material.Light">
    <!-- Override the android colour scheme etc. -->
    <item name="android:colorPrimary">@color/color_primary</item>
</style>

To remove the Action bar and title add to styles.xml:

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

Then in your AndroidManifest.xml you can use your custom theme with or without the action bar

<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...