Title bar keeps appearing, even with requestWindowFeature or android:theme

14,158

Solution 1

Put:

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

Under your application tab, not your activity one

Solution 2

Use your theme in your activity on the AndroidManifest not in your Layout!!

This will work: SplashScreen.java

public class SplashScreen extends Activity{


    private Handler handler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launcher);

        final Runnable runnable = new Runnable() {

            @Override
            public void run() {
                   Intent intent=new Intent(SplashScreen.this, AndroidDashboardDesignActivity.class);
                   startActivity(intent);
                   finish();

            }
        };
        handler = new Handler();
        handler.postDelayed(runnable, 5000);


    }

theme.xml

<style name="SplashTheme" parent="android:Theme">
    <item name="android:windowBackground">@null</item>
    <item name="android:windowNoTitle">true</item>
</style>

<style name="SplashTheme.FullScreen" parent="android:Theme">
    <item name="android:windowBackground">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

the first theme will show the status bar for you if you want to hide this one also use the second theme.Also i have used the attribute windowBackround to null because you will use your image as a backround for your RootLayout after that, so it's better to not override the background color used by the default android theme for performance issue.

in your splashscreen_layout you can use this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/splash"
    android:orientation="vertical" >

</RelativeLayout>

In your manifest use this

<uses-sdk android:minSdkVersion="8" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:icon="@drawable/icone"
    android:label="@string/app_name" >
    <activity
        android:name="com.androidhive.dashboard.SplashScreen"
        android:label="@string/app_name"
        android:theme="@style/SplashTheme"
        android:windowSoftInputMode="stateHidden|adjustResize" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

if you want to use the second theme change in your manifest

android:theme="@style/SplashTheme" with android:theme="@style/SplashTheme.FullScreen"

A Simple way remove or you style tag in your layout and add android:theme="@android:style/Theme.NoTitleBar" in your Manifest under activity tag

Solution 3

With AppCompat this seems works differently.

Following solution worked for me:

Add new theme style with no action bar in your styles.xml and set parent="Theme.AppCompat.NoActionBar".

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/colorPrimary</item>

</style>


Now implement the same theme style to your splash screen activity in androidManifest.xml

<activity
        android:name=".ActivityName"
        android:theme="@style/SplashTheme"> // apply splash them here 

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

Here is result:

enter image description here

Solution 4

based on Krunal solution you can simply put this line inside the <activity> tag in activity.xml file:

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

I.E. replace: android:theme="@style/SplashTheme"

with:

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

inside

<activity
        android:name=".ActivityName"
        android:theme="@style/SplashTheme"> // replace this line

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

giving:

<activity
            android:name=".ActivityName"
            android:theme="@style/Theme.AppCompat.NoActionBar"> // line replaced

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

this saves you from adding anything to styles.xml .

Share:
14,158
Lucas Jota
Author by

Lucas Jota

Updated on June 05, 2022

Comments

  • Lucas Jota
    Lucas Jota about 2 years

    My question is exactly the sabe as Custom titlebar - system titlebar being shown for a brief moment?

    But I couldn't achieve the same results as @Jerry wrote on best answer. "When I switched to using a theme to tell the framework I didn't want a title, the problem went away and I now see my own title directly on first load"

    My code:

    Manifest:

    <?xml version="1.0" encoding="UTF-8"?>
    <manifest android:versionCode="3" android:versionName="1.0.2"
    package="androidhive.dashboard"     xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-sdk android:minSdkVersion="8"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application android:icon="@drawable/icone" android:label="@string/app_name">
        <activity 
            android:name="com.androidhive.dashboard.SplashScreen"
            android:theme="@android:style/Theme.NoTitleBar"
            android:label="@string/app_name"
            android:windowSoftInputMode="stateHidden|adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    

    layout:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    style="@style/SplashTheme"
     >
    
    <ImageView
    android:id="@+id/splashscreen_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="fill_vertical"
    android:contentDescription="Splash"
    android:scaleType="centerCrop"
    android:src="@drawable/splash"
    style="@style/SplashTheme" />
    
    </LinearLayout>
    

    Style:

    <style name="SplashTheme" parent="@android:Theme.Black">
    <item name="android:windowNoTitle">true</item>
    <item name="android:background">@drawable/splash</item>
    </style>
    

    SplashScreen.java

    public class SplashScreen extends Activity implements Runnable{
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setTheme(R.style.SplashTheme);
        setContentView(R.layout.splashscreen_layout);
    
    
    
    
        Handler h = new Handler();
        h.postDelayed(this, 15000);
    }
    
    @Override
    public void run() {
        startActivity(new Intent(this, AndroidDashboardDesignActivity.class));
        finish();
    }
    }
    

    Thank you for helping!