I created a Layout and a Activity to that Layout.
In the Layout I only have an ImageView with a png image that is located in the Resources/Drawables.
When I launch the Application in my Device the ImageView doesn´t appear on the screen.
This is my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:gravity="center"
android:visibility="visible"
tools:visibility="visible">
<ImageView
android:layout_width="350.0dp"
android:layout_height="279.5dp"
android:id="#+id/OpeningLogo"
android:layout_gravity="center"
android:visibility="visible"
tools:visibility="visible"
android:src="#drawable/logo"
android:adjustViewBounds="true" />
</LinearLayout>
This is the Activity Code:
namespace *********
{
[Activity(Label = "xxxxxxxxx", MainLauncher = true, Icon = "#drawable/Logo")]
public class OpeningActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Opening);
Intent GoToLogin = new Intent(this, typeof(MainActivity));
Thread.Sleep(5000);
this.Finish();
StartActivity(GoToLogin);
}
}
}
If you want me to put something more tell me.
Thanks in advance!
Problem is that you are blocking the UI thread of that Activity and it is never actually shown as intended. The UI thread does not get time to actually draw anything on the screen.
Instead you should do something like:
namespace GridSocios
{
[Activity(Label = "xxxxxxxxx", MainLauncher = true, Icon = "#drawable/Logo", NoHistory = true)]
public class OpeningActivity : Activity
{
protected override async void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Opening);
await Task.Delay(5000);
var intent = new Intent(this, typeof(MainActivity));
StartActivity(intent);
}
}
}
Also notice the NoHistory = true flag is set. This means that you can't navigate back to this Activity after you have navigated away from it.
Related
I'm developing an android app and using a shared element transition between the splash screen activity and my login activity. while the transition is happening i get to see the background of my phone, apps and everthing, the only thing that i can see from my application is the logo animation, everything else, gone.
Here is my code:
Splash Screen (Origin)
<LinearLayout
android:id="#+id/meofat_logo"
android:layout_width="86dp"
android:layout_height="86dp"
android:layout_gravity="center"
android:background="#drawable/meofat_logo"
android:orientation="vertical"
android:layout_marginTop="210dp"
android:elevation="24dp"
android:transitionName="logo"/>
<LinearLayout
android:id="#+id/meofat_tipo"
android:layout_width="160dp"
android:layout_height="50dp"
android:background="#drawable/meofat_tipo"
android:layout_gravity="center"
android:elevation="24dp"
android:transitionName="tipo"/>
Login Screen (Destination)
<LinearLayout
android:id="#+id/meofat_logo"
android:layout_width="58dp"
android:layout_height="58dp"
android:layout_gravity="center"
android:background="#drawable/meofat_logo"
android:orientation="vertical"
android:layout_marginTop="80dp"
android:elevation="24dp"
android:transitionName="logo"/>
<LinearLayout
android:id="#+id/meofat_tipo"
android:layout_width="106dp"
android:layout_height="33dp"
android:background="#drawable/meofat_tipo"
android:layout_gravity="center"
android:elevation="24dp"
android:transitionName="tipo"/>
SplashScreen Code:
public class RedirectActivity extends Activity {
private static int SPLASH_TIME_OUT = 2000;
LinearLayout logo,tipo;
Animation upToDown;
Animation downToUp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_redirect);
logo = (LinearLayout) findViewById(R.id.meofat_logo);
tipo = (LinearLayout) findViewById(R.id.meofat_tipo);
upToDown = AnimationUtils.loadAnimation(this,R.anim.uptodown);
logo.setAnimation(upToDown);
downToUp = AnimationUtils.loadAnimation(this,R.anim.downtoup);
tipo.setAnimation(downToUp);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
MEOFatSession session = new MEOFatSession(RedirectActivity.this);
if (session.isLoggedIn()){
Intent goToMeasurement = new Intent(RedirectActivity.this,
MeasurementActivity.class);
RetrofitInitializer.getInstance().addCredentials(session.getCredentials());
startActivity(goToMeasurement);
finish();
} else {
Intent goToLogin = new Intent(RedirectActivity.this,
LoginActivity.class);
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.
makeSceneTransitionAnimation(RedirectActivity.this,findViewById(R.id.meofat_logo),
"logo");
startActivity(goToLogin, optionsCompat.toBundle());
finish();
}
}
},SPLASH_TIME_OUT);
}
}
A gif trying to illustrate the problem.
https://giphy.com/gifs/d1G6hKgTAsX5hOo0
Removing the finish() method solved the issue. Apparently it would destroy the activity during the animation causing it to vanish.
Like #GaboSampaio said, finish() caused the flickering. You can delay it :
Handler handler = new Handler();
handler.postDelayed(this::finish, 1000);
Intent goToLogin = new Intent(RedirectActivity.this, LoginActivity.class);
ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
RedirectActivity.this,
// Now we provide a list of Pair items which contain the view we can transitioning
// from, and the name of the view it is transitioning to, in the launched activity
new Pair<View, String>(findViewById(R.id.logo_splash),
"tipo"));
ActivityCompat.startActivity(RedirectActivity.this, intent, activityOptions.toBundle());
Im developing a contacts app, and for now Ive been trying to get this drawables from the array get uploaded into the Gridview on the main screen AFTER the save mosaic button is clicked in the mosaic creation screen.
the floating action button (red plus button) on the mosaicListScreen (main screen) leads to the MosaicCreationScreen). the user hypothetically uploads the image and enters the mosaic name then saves using the save mosaic button, as can be seen in the image here
For now, before I focus on uploading image and letting the user create their own unique mosaics (groups), Im testing the Gridview updating with some drawables, which are listed in the array as can be seen in the code below.
The issue thats occuring is as soon as the user clicks the floating action button on the main screen, it updates the gridview with the drawables listed in the array of the MosaicCreation Screen, THEN it goes to the MosaicCreationScreen, and when save mosaic button is clicked on the MosaicCreationScreen, the intent goes to the main screen as its supposed to do, except the gridview will have nothing on it.
so its like its doing the opposite of whats supposed to happen in steps.
here is my code for the two screens:
public class mosaicsListScreen extends AppCompatActivity {
public static mosaicsListScreen theScreen; //this variable is used in the MosaicCreationScreen to point to this screen to find the GridView by id
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
theScreen = this;
setContentView(R.layout.activity_mosaics_list_screen);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.createMosaicButton);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(),MosaicCreationScreen.class);
startActivity(intent);
finish();
}
});
}
}
here is the code for the MosaicCreationScreen (the one that opens after user clicks floating action button from mosaicListScreen (main screen))
public class MosaicCreationScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mosaic_creation_screen);
final GridView mosaicList = (GridView) mosaicsListScreen.theScreen.findViewById(R.id.mosaicList);
mosaicList.setAdapter(new ImageAdapter(this)); //this line of code displays the mosaics on mosaicListScreen
Button saveNewMosaicButton = (Button) findViewById(R.id.saveNewMosaicButton);
saveNewMosaicButton.setOnClickListener(new AdapterView.OnClickListener() {
#Override
public void onClick(View view) {
//mThumbIds.notify();
Intent intent = new Intent(getApplicationContext(), mosaicsListScreen.class);
startActivity(intent);
finish();
//mosaicList.setAdapter(new ImageAdapter(this)); //this displays the mosaics on mosaicListScreen, it logically should go here, however "this" causes an error saying ImageAdapter (android.content.Context) in ImageAdapter cannot be applied to (anonymous android.view.View.OnClickListener)
Toast.makeText(mosaicsListScreen.theScreen, "Mosaic Created!", Toast.LENGTH_SHORT).show();
}
});
/* mosaicList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(mosaicsListScreen.theScreen, "", Toast.LENGTH_SHORT).show();
}
});*/
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
//this array holds the drawables that would appear on the Gridview
private Integer[] mThumbIds = {
R.drawable.family,
R.drawable.project
};
}
}
Here are the XML for the layouts:
content_mosaics_list_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="codesages.mosaic.mosaicsListScreen"
tools:showIn="#layout/activity_mosaics_list_screen">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/create_a_mosaic_or_pick_from_the_mosaics_created"
android:id="#+id/textView4"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="20sp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/deleteMosaicButton"
android:src="#android:drawable/ic_menu_delete"
android:clickable="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="" />
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="14dp"
android:id="#+id/mosaicList"
android:layout_above="#+id/textView7"
android:numColumns="auto_fit" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/holdMosaictoDeleteLabel"
android:id="#+id/textView7"
android:layout_marginBottom="16dp"
android:layout_above="#+id/deleteMosaicButton"
android:layout_centerHorizontal="true" />
</RelativeLayout>
activity_mosaics_list_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="codesages.mosaic.mosaicsListScreen">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/createMosaicButton"
android:layout_width="56dp"
android:layout_height="66dp"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_input_add" />
<include layout="#layout/content_mosaics_list_screen" />
</android.support.design.widget.CoordinatorLayout>
activity_mosaic_creation_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="codesages.mosaic.MosaicCreationScreen"
android:focusable="true">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mosaicNametextField"
android:hint="Mosaic Name"
android:layout_marginTop="81dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save New Mosaic"
android:id="#+id/saveNewMosaicButton"
android:layout_marginTop="48dp"
android:layout_below="#+id/uploadMosaicImageButton"
android:layout_centerHorizontal="true"
android:enabled="true"
android:clickable="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Upload Mosaic Image"
android:id="#+id/uploadMosaicImageButton"
android:layout_marginTop="68dp"
android:layout_below="#+id/mosaicNametextField"
android:layout_centerHorizontal="true"
android:enabled="true"
android:clickable="true" />
</RelativeLayout>
mosaicList.setAdapter(new ImageAdapter(this));
thats what appears to be creating the mosaics. if i comment this out, i wont see anything in the gridview.
however, i believe that should be inside the saveNewMosaicButton onClick, but I am getting an error that says "saying ImageAdapter (android.content.Context) in ImageAdapter cannot be applied to (anonymous android.view.View.OnClickListener)"
HERE is an image example of what the desired result should be. however whats happening right now is as ive stated, as soon as the floating action button is clicked, the mosaics are created, THEN it takes you to the creation screen, in which wehn i click save mosaics, it actually erases the mosaics...a job of the trash icon which is too soon to function for now heh.
appreciate help on this
Currently, you have
public static mosaicsListScreen theScreen;
in your first Activity which you use to fill the ListView in this first Activity. This is a dangerous approach because the Activity instance referenced by this variable may be destroyed, for example if you're doing work in your second Activity (e.g. downloading images) which uses much memory, but also if the user somehow triggers a configuration change.
As you are calling finish() after starting the second Activity, you even tell the system that the first Activity may be destroyed. The only reason you did not get a NPE is that the system destroys the finished Activity not instantly but as soon as it seems a good idea to do so.
All in all, you need a way to safely transmit information from one Activity to the other. In your case, I think you would like to send the Uri of the selected images ( or for now, send the resource id of the selected drawables). Both can be accomplished by using Intent extras.
Basically, there are two options:
use startActivityForResult() and override onActivityResult() to obtain the desired information for the first Activity
simply start the first Activity from the second Activity once you have the result and use getIntent() in the first Activity (e.g. in onCreate()) to check for results
No matter what you do, always access UI elements like the ListView in the Activity to which they belong!
If you choose the second option, your first Activity could look like this:
public class mosaicsListScreen extends AppCompatActivity {
public static final String THUMB_IDS = "someuniquestring";
private GridView mosaicList;
private ArrayList<Integer> mThumbIds;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mosaics_list_screen);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.createMosaicButton);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(),MosaicCreationScreen.class);
startActivity(intent);
finish();
}
});
fillThumbIds();
mosaicList = (GridView) findViewById(R.id.mosaicList);
// Note: Adapter code in this Activity
mosaicList.setAdapter(new ImageAdapter(this));
}
private void fillThumbIds()
{
mThumbIds = new ArrayList();
// somehow get older thumb ids if necessary (from database?)
// and add to ArrayList like this:
mThumbIds.add(R.drawable.family);
mThumbIds.add(R.drawable.project);
// assuming we transmit resource id's: use an int array with the Intent
int[] newThumbIds = getIntent().getIntArrayExtra(THUMB_IDS);
if (newThumbIds != null)
{
// loop through the array to add new thumb ids
for (int i = 0; i < newThumbIds.length; i++) {
mThumbIds.add(newThumbIds[i]);
}
}
}
// Adapter code goes here
// Note: thumbIds no longer as array but as ArrayList!
}
In the second Activity, you put the selected thumb ids as Intent extra as follows:
saveNewMosaicButton.setOnClickListener(new AdapterView.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), mosaicsListScreen.class);
// if 'myNewThumbs' is the int array with the new thumb ids
intent.putExtra(mosaicsListScreen.THUMB_IDS, myNewThumbs);
startActivity(intent);
finish();
}
});
I want to display a splash screen for x seconds at the app launch from a PNG file on the device.
I have tried android:windowBackground in the theme however that cannot be taken from a file and only predefined Drawable
The file may change at anytime so at next app launch it will be different.
Below is the code to set timer for Splash Screen activity. Also, do not forget to include the activity in manifest.
splash_screen.java
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
Thread timerThread = new Thread(){
public void run(){
try{
sleep(5000); //Change the timing of the Screen
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent(SplashScreen.this,MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
}
Make your layout, full screen, remove action bar. Here's the code for splash_screen.xml
<?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"
android:background="#drawable/splashscreen"
android:orientation="vertical">
</LinearLayout>
Change the image of splashscreen, when you need, in your case, each time app is launched. HTH.
You can use ImageView.
Set scale image to fit the screen.
Make window fullscreen with no titlebar. By this you can set drawable different every time.
<?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"
android:background="#drawable/splashscreen"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/image2"
/>
</LinearLayout>
Access this ImageView in splash screen activity by..
ImageView img = (ImageView) findviewbyId(R.id.imageView);
Bitmap bitmapImage = BitmapFactory.decodeFile(imagePathFromSDCard);
Drawable drawableImage = new BitmapDrawable(bitmapImage);
img.setBackgroundDrawable(drawableImage);
i have the following code and it works great for android 4.4 KitKat.
In the other android version the animation #anim/loading_animation is showing but not moving.
Someone can help me?? Thank you so much!!
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 4000;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
splash_screen.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/Black" >
<ImageView
android:id="#+id/logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:contentDescription="#string/image"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:src="#anim/loading_animation" />
</RelativeLayout>
Just check your manifest file and minimum SK version. Change it to API 8.I hope it works.
If you still face any issue. let me know
Alright, so I have a splash screen on my app. I was wondering if there was a way for me to have it where it only appears the first initial time the app opens (or if they force close it and such), and so that way if they press the back key, it doesn't take them to the splash screen.
I can make it so the user cant go back to the splash screen by just typing finish() and, though I cant remember it right now, I can make it where it only loads once. Once I call finish(), the splash will reappear upon reentering the app. Is there any way to fix this?
Yes, you can do that by calling finish() on the onPause method of your splashActivity.
Or another way to do this is to add android:noHistory="true" on splashActivity of your manifest.xml
With a SplashScreenActivity you're wasting time because they pause the initialization for 2-3seconds before they continue.
I prefer adding a Splash Screen Layout on top of my main_activity.xml. I detect the first start of the application by extending Application. If it´s the first start, I show my Splash-Screen while the UI is build in the background... (Use background threads if the ProgressBar lags!)
//Extend Application to save the value. You could also use getter/setter for this instead of Shared Preferences...
public class YourApplication extends Application {
public static final String YOUR_APP_STARTUP = "APP_FIRST_START";
#Override
public void onCreate() {
super.onCreate();
//set SharedPreference value to true
SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(YOUR_APP_STARTUP, true);
editor.apply();
...
}
Check for your first start in your MainActivity
public class YourMainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//hide actionbar and other menu which could overlay the splash screen
getActionBar().hide();
setContentView(R.layout.activity_main);
Boolean firstStart = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean(TVApplication.YOUR_APP_STARTUP, true);
if (firstStart) {
//First app start, show splash screen an hide it after 5000ms
final RelativeLayout mSplashScreen = (RelativeLayout) findViewById(R.id.splash_screen);
mSplashScreen.setVisibility(View.VISIBLE);
mSplashScreen.setAlpha(1.0f);
final FrameLayout mFrame = (FrameLayout) findViewById(R.id.frame_container);
mFrame.setAlpha(0.0f);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Animation fadeOutAnimation = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_out_animation);
fadeOutAnimation.setDuration(500);
fadeOutAnimation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
mFrame.setAlpha(1.0f);
getActionBar().show();
}
#Override
public void onAnimationEnd(Animation animation) {
mSplashScreen.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
mSplashScreen.startAnimation(fadeOutAnimation);
}
}, 5000); //<-- time of Splash Screen shown
} else {
((RelativeLayout) findViewById(R.id.splash_screen)).setVisibility(View.GONE);
getActionBar().show();
}
Insert the SplashScreen at top in your main.xml. I prefer RelativeLayout for that. In the example, SplashScreen is placed on to of a layout with the Navitgation Drawer, which we really love, don`t we?
//main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main content view -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer list -->
<ListView
android:id="#+id/slider_list"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_gravity="start"
android:background="#color/tvtv_background"
android:choiceMode="singleChoice"
android:divider="#drawable/nav_bar_divider"
android:dividerHeight="1dp"
android:listSelector="#android:color/transparent" />
</android.support.v4.widget.DrawerLayout>
<RelativeLayout
android:id="#+id/splash_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:background="#color/tvtv_white"
android:visibility="visible" >
<ImageView
android:id="#+id/splash_screen_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/splash_screen_text"
style="#style/TVTextBlueContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/splash_screen_logo"
android:layout_centerHorizontal="true"
android:padding="10dp"
android:text="Awesome splash shiat" />
<ProgressBar
android:id="#+id/splash_screen_loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/splash_screen_text"
android:layout_centerHorizontal="true"
android:clickable="false"
android:indeterminate="true" />
</RelativeLayout>
</RelativeLayout>