Android:如何为APP添加满屏启动页

来源:互联网 发布:路由器网络不稳定 编辑:程序博客网 时间:2024/05/16 05:49


1、首先,我们创建一个布局splash.xml;

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <ImageView        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:scaleType="fitXY"        android:src="@drawable/splash">    </ImageView></LinearLayout>

2、再者,创建一个新类SplashActivity.java;

public class SplashActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.splash);Handler hd = new Handler();          hd.postDelayed(new splashhandler(), 800);}class splashhandler implements Runnable {public void run() {startActivity(new Intent(getApplication(), MainActivity.class));SplashActivity.this.finish();}}}


3、在manifest中配置我们的启动入口;

<activity android:name="x.x.x.SplashActivity"            android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale"            android:label="@string/app_name"            android:launchMode="singleTask"            android:screenOrientation="landscape" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />            </intent-filter>        </activity>

最后不要忘了要首屏的图片资源drawable/splash.png;

综上,我们APP的启动页已经做好了。


0 0
原创粉丝点击