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

5

6

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!

Trant answered 26/6, 2012 at 21:23 Comment(0)
C
7

Put:

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

Under your application tab, not your activity one

Confectionary answered 26/6, 2012 at 21:27 Comment(1)
It's so simple so only author can understand himself!Shipman
I
9

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

Interblend answered 26/6, 2012 at 21:58 Comment(1)
Thank you! As long as I didn't want a custom title, @Cruceo's answer worked fine. But yours is very complete and well-explained, and may help those who want custom titles.Trant
C
7

Put:

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

Under your application tab, not your activity one

Confectionary answered 26/6, 2012 at 21:27 Comment(1)
It's so simple so only author can understand himself!Shipman
S
1

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

Shoa answered 22/12, 2017 at 15:0 Comment(0)
T
1

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 .

Tigre answered 7/7, 2018 at 14:4 Comment(0)
W
0

In your MainActivity use this

 getSupportActionBar().hide();
   getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Warmhearted answered 30/11, 2017 at 11:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.