Sumber Kode

Splash Screen

  • anonymous
  • Oct 22' 13
  • Android
  • 951
  • 14
  • United States

Creating splash screen for android
like when we run ms-office at the beginning will appear a splash a few minutes before loading the entire file needed by the program, and could make a splash like this in android

splash.java file :

package com.pasarkode.splash;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.MotionEvent;
 
public class Splash extends Activity {
    protected boolean _active = true;
    protected int _splashTime = 2000;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.splash);
        
        // thread for displaying the SplashScreen
        Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    Intent newIntent=new Intent(Splash.this, Coba.class);
            		startActivityForResult(newIntent,0);
                }
            }
        };
        splashTread.start();
    }
 
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            _active = false;
        }
        return true;
    }
}



Coba.java

package com.pasarkode.splash;

import android.app.Activity;
import android.os.Bundle;
 
public class Coba extends Activity {
  public void onCreate(Bundle savedInstanceState){
	super.onCreate(savedInstanceState);
	setContentView(R.layout.coba);
  }
  }

coba.xml file

<?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:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Coba splash" />

</LinearLayout>

splash.xml file :

note:for the portion of the image that is used to create a splash png files with names splash.png

<?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:gravity="center|center_horizontal"
    android:background="@drawable/splash">

    <ProgressBar
        android:id="@+id/progressBar2"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.splash"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
       
        <activity
            android:name=".Splash"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
        </activity>
        
        <activity
            android:name=".Coba">
            </activity>
        
     </application>
</manifest>

happy try

Share

  • Tags :
comments powered by Disqus

Kode Terkait

Border Radius

Session for Keep Values

Solve (LSN) Error 9003 When Attach the Database SQL2000

Zakat Counter

Looking for Date and Time Difference

Send Email Through Console

Program mencari kpk n buah bilangan

Membuat program bilangan n prima

Piramida angka

Error 945 SQL Server 2008



Kategori