Hurriyet Spor

Bumerang - Yazarkafe

Splash Açılış Ekranı Eklemek

 

Programın direk açılmaması ve açılışta yapılan işlemleri gölgeleyip beyaz ekran görünmesi yerine progressbar'lı splash ekranı gözükmesini sağlayabiliriz. Burada splash dosyamız Main Activity dosyası olacaktır. İlk açılacak olan eylem dosyamız. Dosyanın adı Acilis.java olabilir.

Acilis.java

 
package splashuygulama.com;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class Acilis extends Activity {

private static String TAG = Acilis.class.getName();
private static long SLEEP_TIME = 2; // Gecikme Süresi

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_splash);


IntentLauncher launcher = new IntentLauncher();
launcher.start();
}

private class IntentLauncher extends Thread {
@Override

public void run() {
try {
// Sleeping
Thread.sleep(SLEEP_TIME*1000);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}

// Start main activity
Intent intent = new Intent(Acilis.this, Canlitv.class);
Acilis.this.startActivity(intent);
Acilis.this.finish();
}
}
}

 
activity_splash.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/canlitv"
android:orientation="vertical" >

<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />


</RelativeLayout>

Manifest Dosyası

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

<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="androidcanlitv.com.Acilis"
android:label="@string/app_name">


<intent-filter>

Artık program açılırken resimli açılış ekranı gelecektir. Gecikme sayinesi koddan ayarlanabilir.

Hiç yorum yok:

Yorum Gönder