Scale Animation Help - Android Software Development

Unrelated to my other Animation based thread but I cant seem to figure out how to run my animation that i created on an ImageView..
I created this scaling animation in XML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
<scale android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" android:duration="150" />
<scale android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0" android:toYScale="0.0" android:duration="150" android:delay="5000" />
</set>
and the image view in my main.xml file:
Code:
<ImageView android:id="@+id/Logo" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center_vertical|center_horizontal|center" android:src="@drawable/logo"></ImageView>
I haven't found the best documentation for this, so im probably trying to run this completely wrong, but here's what i did to attempt to run it as the app starts up:
Code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Animation anim = AnimationUtils.loadAnimation(this, R.anim.logozoom);
View logo = findViewById(R.id.Logo);
setContentView(R.layout.launch);
logo.startAnimation(anim);
}
Where am I failing?
Thanks for the help
EDIT: I fixed it! if anyone else runs into problems with this just PM me and il update this post, too lazy right now

Related

GoogleMap-Android

Hi all,
I am trying to get map in android Emulator, But I have error message when i run the application.How to rectify this error?
My Code:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.googlemapsandroid"
android:versionCode="1"
android:versionName="1.0">
<uses-library android:name="com.google.android.maps.map" />
<application android:icon="@drawable/worldmap" android:label="@string/app_name">
<activity android:name=".GoogelMapsAndroid"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0ubDx0zU6vaeSSZoV0oyPB4zi7y8T2hKSZfAyZw"
/>
</RelativeLayout>
GoogleMapsAndroid.java
package com.android.googlemapsandroid;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class GoogleMapsAndroid extends MapActivity
{
MapView mapview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapview=(MapView)findViewById(R.id.mapview);
mapview.setSatellite(true);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
I have error message:
java lang Runtime Exception Unable to instantiate ComponentInfo{com.android.googlemapsandroid/com.android.googlemapsandroid.MapsActivity}java.lang.RuntimeException: stub
Do you use Google APIs target in an emulator?
No. How to use Google api.
dineshsubramanian said:
No. How to use Google api.
Click to expand...
Click to collapse
This is what I mean:
http://img40.imageshack.us/f/screenshotcreatenewandr.png/
Thanks for your reply.
I will try in Google Api.
Now i ran in google api. but i have error message
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.googlemapdemo/com.googledemo.GoogleMapDemo}: android.view.InflateException: Binary XML file line #6: Error inflating class com.google.android.maps.MapView.

[Q] MapView-No Map Display

I am new to SW development with Android.
Trying to have a MapView object in my display. Code is straightforward below. But for some reason when i launch the application i do not see any map but rather the grey grid.
I have looked at many posts on the internet and i understand that it is either an INTERNET permission (which is included in my coe) or a wrong apiKey. I have gone through the apiKey several time.
Am not sure what can be wrong. Any help would be great. Thanks, Lebnen.
-----------------------------------------------
Manifest.xml
-----------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.testmap"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<uses-library android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.INTERNET" />
<activity android:name=".TestMapActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
-----------------------------------------------
main.xml
-----------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
>
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:enabled="true"
android:apiKey="0SA_n7tIj-klgGxARuFJgEos8FBGtEshpgmfogA"
/>
</LinearLayout>
-----------------------------------------------
testMapActivity.java
-----------------------------------------------
package com.test.testmap;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.LinearLayout;
import com.google.android.maps.MapView;
import com.google.android.maps.MapController;
import com.google.android.maps.MapActivity;
import com.google.android.maps.GeoPoint;
public class TestMapActivity extends MapActivity {
private MapView mapView;
LinearLayout linearLayout;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mapView = (MapView) this.findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
}
@Override
public boolean isRouteDisplayed() { return false; }
}
Dont see your manifest. Is it a dev map key ? Is the application debuggable in the manifest ?
Sent from my Nexus One using XDA App
1. What do you mean by dev map key? Am using the debug.keystory MD5 hash that I feed into the google page http://code.google.com/android/add-ons/google-apis/maps-api-signup.html to get the apiKey.
2. The application is debbugable in the manifest.
Ok i see your files on computer now (not on android application on my nexus one)
replace com.google.android.maps.MapView by com.test.testmap.testMapActivity
If I replace it in main.xml the application crashes; in the manifest it does not compile
Help!
the:
<uses-permission android:name="android.permission.INTERNET" />
you have to put on <manifest>, not on <application>
like
<manifest ...>
<application ...>
<uses-library android:name="com.google.android.maps" />
.
.
.
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Other thing that I'm not totally right if it's correct:
I don't know if this is correct, but for me, only worked when I create a new Android Project with Target on Google API's. Didn't work with Android 2.2 + map.jar.
Did you create with Android X.X or Google API ?
I have tried to put the INTERNET permission inside and outside the application. It does not make a difference.
I am building a Google API application.
It worked.
Weird. I had to add
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
in <manifest> outside of <application> and did it through the "Permissions" tab in Eclipse.
Thanks.
Interesting, because I thought that the "ACCESS_FINE_LOCAT ION" is used only when you try to use something with location, such as get location, distance between locations, etc..., I thought that it's not necessary when you only want to show the map
Good to know, thank you

[Q] ListView with BaseAdapter not showing

Hi I have used ListFragment and simple ArrayAdapter quite often. And now I want to try some more by customizing BaseAdapter. But something happened, the List is not showing at all. I don't have any error (the Logcat also saying there're no error). But I debug it, and found out that getView() in my customized BaseAdapter is not called. I wonder why?
Here's the snippet:
#favorite_list_layout
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="@+id/favorite_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
#favorite_list_item
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/favorite_text"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="0dp"
android:textSize="35sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/favorite_text_details"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif-light"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
#FavoritesFragment
Code:
public class FavoritesFragment extends ListFragment {
[user=439709]@override[/user]
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//... setting variable favList, and this code is working. favList is not empty and there're no error
setListAdapter(new FavoriteAdapter(getActivity(), favList));
}
}
FavoriteAdapter, extends BaseAdapter
Code:
public class FavoriteAdapter extends BaseAdapter {
private Context ctx;
List<DMapData> list;
public FavoriteAdapter(Context context, List<DMapData> list) {
this.ctx = context;
this.list = list;
System.out.println("constructor executed!");
}
[user=439709]@override[/user]
public int getCount() {
return list.size();
}
[user=439709]@override[/user]
public Object getItem(int i) {
return list.get(i);
}
[user=439709]@override[/user]
public long getItemId(int i) {
return i;
}
[user=439709]@override[/user]
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("GetView is executed"); //But it's not.
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.favorite_list_item, parent, false);
}
TextView favText = (TextView) rowView.findViewById(R.id.favorite_text);
TextView detailsText = (TextView) rowView.findViewById(R.id.favorite_text_details);
DMapData data = list.get(position);
System.out.println("DMapData from List");
favText.setText(data.getName());
detailsText.setText(data.getDetails().length()<=50? data.getDetails() : data.getDetails().substring(0, 51).concat("..."));
System.out.println("At the end of getView()");
return rowView;
}
}
Thanks
The id of the ListView has to be a special one so that the ListFragment can find it:
Code:
android:id="@android:id/list"
Hmm...
I have tried to change the id like your code. But, still not shown up. Is there anything I should do with my ListFragment?
nikwen said:
The id of the ListView has to be a special one so that the ListFragment can find it:
Code:
android:id="@android:id/list"
Click to expand...
Click to collapse
JoshieGeek said:
Hmm...
I have tried to change the id like your code. But, still not shown up. Is there anything I should do with my ListFragment?
Click to expand...
Click to collapse
Do you inflate your layout?
Code:
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_layout, container, false);
}
I always set the adapter in onCreate but there shouldn't be a difference.
Your layout looks like that now, right?
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
EDIT: Oh, add an orientation to the LinearLayout or replace it by a RelativeLayout.
And change the ListView heigth to match_parent.
Yupz. But still no different.
Here's my changed code. I have changed not using my customized adapter again, but instead using SimpleAdapter.
/res/layout/favorite_list_layout.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/res/layout/favorite_list_item
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/favorite_text"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="0dp"
android:textSize="35sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/favorite_text_details"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif-light"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/src/.../AllFragment.java
Code:
public class AllFragment extends ListFragment {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO get All Data
//Let's just adopt Favorite List Adapter for now
MasterDataReader mdReader = new MasterDataReader();
mdReader.execute();
List<DMapData> allList = new ArrayList<DMapData>();
allList.add(new DMapData("Empty", "No data found!"));
try {
allList = mdReader.get();
System.out.println("All List received");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
List<Map<String, String>> finList = new ArrayList<Map<String, String>>();
for(DMapData data : allList) {
Map<String, String> m = new HashMap<String, String>();
m.put("name", data.getName());
m.put("detail", data.getDetails().length()<=50? data.getDetails() : data.getDetails().substring(0, 51).concat("..."));
finList.add(m);
}
String[] colNames = new String[] {
"name", "detail"
};
int[] tView = new int[] {
R.id.favorite_text, R.id.favorite_text_details
};
SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), finList, R.layout.favorite_list_layout,
colNames, tView);
setListAdapter(simpleAdapter);
}
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.favorite_list_layout, container, false);
}
}
What do you think?
nikwen said:
Do you inflate your layout?
Code:
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_layout, container, false);
}
I always set the adapter in onCreate but there shouldn't be a difference.
Your layout looks like that now, right?
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
EDIT: Oh, add an orientation to the LinearLayout or replace it by a RelativeLayout.
And change the ListView heigth to match_parent.
Click to expand...
Click to collapse
JoshieGeek said:
Yupz. But still no different.
Here's my changed code. I have changed not using my customized adapter again, but instead using SimpleAdapter.
/res/layout/favorite_list_layout.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/res/layout/favorite_list_item
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/favorite_text"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="0dp"
android:textSize="35sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/favorite_text_details"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif-light"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/src/.../AllFragment.java
Code:
public class AllFragment extends ListFragment {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO get All Data
//Let's just adopt Favorite List Adapter for now
MasterDataReader mdReader = new MasterDataReader();
mdReader.execute();
List<DMapData> allList = new ArrayList<DMapData>();
allList.add(new DMapData("Empty", "No data found!"));
try {
allList = mdReader.get();
System.out.println("All List received");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
List<Map<String, String>> finList = new ArrayList<Map<String, String>>();
for(DMapData data : allList) {
Map<String, String> m = new HashMap<String, String>();
m.put("name", data.getName());
m.put("detail", data.getDetails().length()<=50? data.getDetails() : data.getDetails().substring(0, 51).concat("..."));
finList.add(m);
}
String[] colNames = new String[] {
"name", "detail"
};
int[] tView = new int[] {
R.id.favorite_text, R.id.favorite_text_details
};
SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), finList, R.layout.favorite_list_layout,
colNames, tView);
setListAdapter(simpleAdapter);
}
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.favorite_list_layout, container, false);
}
}
What do you think?
Click to expand...
Click to collapse
Try this layout:
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"
android:layout_alignParentTop="true"
android:fastScrollEnabled="true" />
<ProgressBar
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="?android:attr/progressBarStyle" />
</RelativeLayout>
It's working for me.
Did you try to write all entries to the logs? Do you get an output?
You know what? This is really make me laugh all the time, that it's because what I think is right but actually not. The list that I provided for my ListView is actually empty. Your layout tell me, because there's always the progressbar. Thank you very much for your help. :highfive:
nikwen said:
Try this layout:
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"
android:layout_alignParentTop="true"
android:fastScrollEnabled="true" />
<ProgressBar
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="?android:attr/progressBarStyle" />
</RelativeLayout>
It's working for me.
Did you try to write all entries to the logs? Do you get an output?
Click to expand...
Click to collapse
JoshieGeek said:
You know what? This is really make me laugh all the time, that it's because what I think is right but actually not. The list that I provided for my ListView is actually empty. Your layout tell me, because there's always the progressbar. Thank you very much for your help. :highfive:
Click to expand...
Click to collapse
Welcome.
I'm glad that you solved that because it began to drive me crazy. :laugh:
@JoshieGeek
consider using Log
Log.i("class/functionName","message you want to display");
Click to expand...
Click to collapse
It will be easy to debug
Sandeep_Jagtap said:
@JoshieGeek
consider using Log
It will be easy to debug
Click to expand...
Click to collapse
Didn't you see that he already solved his problem?
nikwen said:
Didn't you see that he already solved his problem?
Click to expand...
Click to collapse
Yes its quite noticeable
As he was saying he could not see error in Log while debugging. My advice to use log was for his future projects.
Sent from my Incredible S using xda app-developers app
Sandeep_Jagtap said:
Yes its quite noticeable
As he was saying he could not see error in Log while debugging. My advice to use log was for his future projects.
Sent from my Incredible S using xda app-developers app
Click to expand...
Click to collapse
OK.
Check out my guide on debugging here: http://forum.xda-developers.com/showthread.php?t=2325164

[Q] How can custom tab view be implemented using setCustomTabView method

I am using Android's SlidingTabColors sample in my application layout. I have three tabs initialized. Due to the default tab layout all the tabs have same layout. I have searched everything about setCustomTabView; but unable to get it implemented. I wanted to know where should i call this method? What statements are to be used? I have used a switch statement in the onViewCreated method of the ContentFragment class. The code I have written in the onViewCreated method is posted below:
Code:
public void onViewCreated(View view, Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
TextView title = (TextView) view.findViewById(R.id.item_title);
int indicatorColor = args.getInt(KEY_INDICATOR_COLOR);
switch (indicatorColor)
{
case Color.RED:
{
SlidingTabLayout mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);
mSlidingTabLayout.setCustomTabView(R.layout.speed_test, R.id.hello1);
}
case Color.GREEN:
title.setText("Subject: " + args.getCharSequence(KEY_TITLE));
case Color.BLUE:
title.setText("Header: " + args.getCharSequence(KEY_TITLE));
}
}
[CODE]
The speed_test.xml file is posted below:
[CODE]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello"
android:id="@+id/hello1"
/>
</RelativeLayout>
[CODE]

[Tutorial] Create a Splash Screen on Android : the Right Way !

Hello,
I create that thread to present you a tutorial learning you how to create a Splash Screen on Android by following the right way. Note that you can also discover this tutorial in video on Youtube :
Create a Splash Screen on Android : the Right Way !
At a certain moment in the past, Google advised against using a Splash Screen on Android Applications. It was useless. Then, when they have published the Material Design Specifications, some of us have seen that the Splash Screen was now a pattern known as Launch Screen. Ideal to display your brand logo during cold start of applications. So, what’s the difference between the bad Splash Screen and the good Splash Screen ?
The difference is just the way you implement if. Previously, developers implemented the Splash Screen by displaying their brand logo on the screen during a certain time. The right way to implement a Launch Screen is now just to display your brand logo the time the application starts and no more.
To create a correct Splash Screen, you need to create a background that will display your brand logo to the screen. For this, you must create an XML file in the res/drawable folder :
Code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorPrimary" />
<item>
<bitmap android:src="@drawable/logo"
android:gravity="center" />
</item>
</layer-list>
Next step is to create a dedicated theme for your Splash Activity. For this, you must inherit from the Theme.AppCompat.NoActionBar theme :
Code:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background</item>
</style>
</resources>
Note that your Splash Theme has just to define the android:windowBackground item and set up the background created previously.
Now, you can create your SplashActivity :
Code:
package com.ssaurel.splashscreen;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
/**
* Created by ssaurel on 02/12/2016.
*/
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
No need to define a content view for the SplashActivity because you are going to apply the SplashTheme on it. So, you have just to launch the MainActivity of your Android Application and then finish the SplashActivity by calling the finish() method.
Don’t forget to define your SplashActivity in the Android Manifest and apply the SplashTheme on it :
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ssaurel.splashscreen">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashActivity" android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
</application>
</manifest>
Then, you can write the code of your Android Application in your MainActivity as you want. You can try the application by seeing the demo in the previous video. Now, you could make Splash Screen on Android by following the right way !
Don't hesitate to give it a try and give me your feedbacks !
Thanks.
Sylvain

Categories

Resources