I want to display a logo for few seconds before application starts and menu is visible. I want also to use some when it disappears. Should I create a new activity? Can I set it
You can use splash logo at startup using styles-only method. Unfortunately it works only starting form API 23. But you don't need manage splash Activity.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="android:windowBackground">@drawable/logo_startup</item>
<item name="android:windowNoTitle">true</item>
</style>
res/drawable-v23/logo_startup.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/PageBackground"/>
<item android:width="@dimen/logo_startup" android:height="@dimen/logo_startup" android:gravity="center">
<bitmap android:src="@drawable/logo"/> //use PNG file here, not vector
</item>
</layer-list>
res/drawable/logo_startup.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/PageBackground"/>
</layer-list>
Here are a few intros to making a splash-page:
http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/
http://blogingtutorials.blogspot.com/2010/11/splash-graphics-activity-in-android.html
Android SplashScreen
You can use an image view that gets setVisibility(Visibility.GONE); or something to that extent, or you can write an activity that just pops up and drops out after a time ends. That is your personal preference...
package com.karan.android.video;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class splash extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread splashThread = new Thread()
{
@Override
public void run()
{
try {
int waited = 0;
while (waited < 3000)
{
sleep(100);
waited += 100;
}
} catch (InterruptedException e)
{
// do nothing
} finally
{
finish();
Intent i = new Intent(splash.this,video.class);
startActivity(i);
}
}
};
splashThread.start();
}
}
Xml file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/buff"
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:textSize="40dp"
android:textColor="#CCFF00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Buffering..."
/>
</FrameLayout>
define a layout for the splash screen which will contain your logo , and then , add this code to your activity :
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
//display the logo during 5 seconds,
new CountDownTimer(5000,1000){
@Override
public void onTick(long millisUntilFinished){}
@Override
public void onFinish(){
//set the new Content of your activity
YourActivity.this.setContentView(R.layout.main);
}
}.start();
}
Delayed execution can be implemented in simplier way:
new Handler().postDelayed(new Runnable() {
// ... Hide splash image and show the real UI
}, 3000)
Also the android standard android.widget.ViewSwitcher
class is very usable for this kind of things.