Display image before launching an activity -
i need show logo of application before starts 3 seconds , release activity
firstly, need xml layout file hold whatever display on splash screen - example image. how layout splash screen looks , points image made in photoshop.
splash.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:scaletype="centerinside" android:background="@drawable/vtevents"> </linearlayout> you need put image want project folder (maybe like: projectname\app\src\main\res\drawable . it's best if image .png format , name must not have capital letters in it. name image splash_image.png
this how implement splash screen. need provide activity going start after in variable mainactivityname class requires 2 imports:
import android.app.activity;
import android.content.intent;
public class splashactivity extends activity { // splash activity private string mainactivityname = "com.example.mainactivity"; // first activity after splash screen @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.splash); thread logotimer = new thread() { public void run() { try { sleep(2500); intent mainintent = new intent(mainactivityname); startactivity(mainintent); } catch (interruptedexception e) { e.printstacktrace(); } { finish(); } } }; logotimer.start(); } } sleep(2500) tells thread wait 2500ms (2.5seconds) until next activity launched. edit liking.
if managed help, please accept answer question.
Comments
Post a Comment