马会东的博客

马会东的博客

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

转自:http://blog.csdn.net/zhangzhikaixinya/article/details/17001321

 

大部分Android App启动过程中,都会设置一个背景图片,直到App加载成功,图片消失。因此,这也是做Android App的基本技能之一。这个过程实现起来并不难。

总共需要以下内容:2个Activity,一张背景图,2个xml配置文件,String.xml,AndroidManifest写入配置信息。

 

1 准备一张背景图图片,命名为load,自己选择图片格式。放在drawable目录下

 

2  创建Load页面 LoadActivity.java及相关布局文件load.xml

LoadActivity.java

 

[java] view plaincopy
 
 
  1. package com.timothy.load;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.content.Intent;  
  6. import android.graphics.PixelFormat;  
  7. import android.os.Handler;  
  8. import android.view.WindowManager;  
  9.   
  10. public class LoadActivity extends Activity {  
  11.       
  12.     //time for picture display  
  13.     private static final int LOAD_DISPLAY_TIME = 1500;  
  14.       
  15.     /** Called when the activity is first created. */  
  16.     @Override  
  17.     public void onCreate(Bundle savedInstanceState) {  
  18.         super.onCreate(savedInstanceState);  
  19.           
  20.         getWindow().setFormat(PixelFormat.RGBA_8888);  
  21.         getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);  
  22.         setContentView(R.layout.load);  
  23.           
  24.         new Handler().postDelayed(new Runnable() {  
  25.             public void run() {  
  26.                 //Go to main activity, and finish load activity  
  27.                 Intent mainIntent = new Intent(LoadActivity.this, MainActivity.class);  
  28.                 LoadActivity.this.startActivity(mainIntent);  
  29.                 LoadActivity.this.finish();  
  30.             }  
  31.         }, LOAD_DISPLAY_TIME);   
  32.     }  
  33. }  


load.xml

 

 

[html] view plaincopy
 
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2.  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.      android:orientation="vertical"  
  4.      android:gravity="center|center"  
  5.      android:layout_width="fill_parent"  
  6.      android:layout_height="fill_parent"  
  7.      android:background="@drawable/load">  
  8.  </LinearLayout>  


3  创建主页面 MainActivity.java及相关布局文件main.xml 

 

MainActivity.java

 

[java] view plaincopy
 
 
  1. package com.timothy.load;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5.   
  6. public class MainActivity extends Activity {  
  7.     /** Called when the activity is first created. */  
  8.     @Override  
  9.     public void onCreate(Bundle savedInstanceState) {  
  10.         super.onCreate(savedInstanceState);  
  11.         setContentView(R.layout.main);  
  12.     }  
  13. }  


main.xml

 

 

[html] view plaincopy
 
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. <TextView    
  8.     android:layout_width="fill_parent"   
  9.     android:layout_height="wrap_content"   
  10.     android:text="@string/hello"  
  11.     />  
  12. </LinearLayout>  


4 配置strings.xml

 

 

[html] view plaincopy
 
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <string name="hello">Hello, this is a demo to picture before app start</string>  
  4.     <string name="app_name">LoadPictureDemo</string>  
  5.       
  6.     <style name="MyTheme.NoTitleBar.CustomBackground" parent="@android:Theme.Black">    
  7.         <item name="android:windowBackground">@drawable/load</item>    
  8.         <item name="android:windowNoTitle">true</item>    
  9.         <item name="android:windowFullscreen">true</item>    
  10.         <item name="android:windowContentOverlay">@null</item>    
  11.     </style>  
  12. </resources>  


5 配置AndroidManifest.xml

 

 

[html] view plaincopy
 
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.       package="com.timothy.load"  
  4.       android:versionCode="1"  
  5.       android:versionName="1.0">  
  6.     <uses-sdk android:minSdkVersion="8" />  
  7.   
  8.     <application android:icon="@drawable/icon" android:label="@string/app_name">  
  9.          
  10.          <activity android:name=".LoadActivity"  
  11.                   android:configChanges="orientation|keyboardHidden"  
  12.                   android:theme="@style/MyTheme.NoTitleBar.CustomBackground">  
  13.             <intent-filter>  
  14.                 <action android:name="android.intent.action.MAIN" />  
  15.                 <category android:name="android.intent.category.LAUNCHER" />  
  16.             </intent-filter>  
  17.         </activity>  
  18.           
  19.         <activity android:name=".MainActivity">  
  20.         </activity>  
  21.   
  22.     </application>  
  23. </manifest>  


6 OK, 编译运行

 

启动过程中:

完成启动:

posted on 2015-04-16 23:01  马会东  阅读(1385)  评论(0编辑  收藏  举报