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