Sunday, March 13, 2016

101 My Neighbors Apps


.
101 My Neighbors Apps

1) Create New Project

Project Name: MyNeighbors

2) Add Splash Activity

Add a new (empty) activity and give the name SplashActivity.

2.1) Add drawable images

DOWNLOAD: drawable.zip

2.2) Edit Custom Style

This involves creating drawables definition, color and themes.
File: res/drawable/background_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item
       android:drawable="@color/gray"/>
   <item>
       <bitmap
           android:gravity="center"
           android:src="@drawable/neighbors_logo"/>
   </item>
</layer-list>
File: res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
   <color name="colorPrimary">#3F51B5</color>
   <color name="colorPrimaryDark">#303F9F</color>
   <color name="colorAccent">#FF4081</color>
   <color name="gray">#444440</color>
</resources>
File: res/values/styles.xml
<resources>
   <!-- Base application theme. -->
   <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
       <!-- Customize your theme here. -->
       <item name="colorPrimary">@color/colorPrimary</item>
       <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
       <item name="colorAccent">@color/colorAccent</item>
   </style>
   <style name="AppTheme.NoActionBar">
       <item name="windowActionBar">false</item>
       <item name="windowNoTitle">true</item>
   </style>
   <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
   <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
   <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
       <item name="android:windowBackground">@drawable/background_splash</item>
   </style>
</resources>

2.3) Edit Controller

File: SplashActivity.java
package com.notarazi.myneighbors;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SplashActivity extends AppCompatActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_splash);
       Intent intent = new Intent(this, MainActivity.class);
       startActivity(intent);
       finish();
   }
}

2.4) Edit AndroidManifest

... so that the launcher starts with SplashActivity and is using the custom theme.
File: AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.notarazi.myneighbors">
   <application
       android:allowBackup="true"
       android:icon="@mipmap/ic_launcher"
       android:label="@string/app_name"
       android:supportsRtl="true"
       android:theme="@style/AppTheme">
       <activity
           android:name=".MainActivity"
           android:label="@string/app_name"
           android:theme="@style/AppTheme.NoActionBar">
       </activity>
       <activity android:name=".SplashActivity">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
   </application>
</manifest>
OUTCOME.
Splash Screen
Followed by Main Screen
REFERENCE:
In addition to this, we can set a delay timer.
File: SplashActivity.java
package com.notarazi.myneighbors;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class SplashActivity extends AppCompatActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_splash);
       setDelayAndFinish();
   }
   private void setDelayAndFinish() {
       new Handler().postDelayed(new Runnable() {
           // Using handler with postDelayed called runnable run method
           @Override
           public void run() {
               //display in short period of time
               Intent intent = new Intent(SplashActivity.this, MainActivity.class);
               startActivity(intent);
               finish();
           }
       }, 1000); // wait for 3 seconds
   }
}


.

No comments:

Post a Comment