Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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

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>

This is what worked for me

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

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

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>

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

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...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top