2, 在layout布局文件下,配置好我们真正欲显示的布局文件:
<?xml version="1.0"encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"android:background="@drawable/lover"
android:id="@+id/llbg"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
3 , 在AndroidManifest文件中,需要添加功能的此Activity添加Theme属性:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.feixun.cn"
android:versionCode="1"
android:versionName="1.0">
<!—添加Theme属性-->
<application android:icon="@drawable/icon"android:label="@string/app_name" android:theme="@style/Theme.MainActivity" >
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
上面我们已经设置好了构造方式,应用程序的背景界面会立即显示styles中的bg_car.jpg,然后立即转换为layout中的lover.jpg。 当然,如果我们想延长styles的布局文件的时间,我们可以利用Handler来使主线程(UI线程)来睡眠一段时间,然后在setContentView(view)。 具体代码如下:
importandroid.app.Activity;
import android.os.Bundle;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.widget.LinearLayout;
public class MainActivity extends Activity {
private static int WAIT_FOR = 1;
private LinearLayout ll;
/** Called whenthe activity is first created. */
@Override
public void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
// 利用handler来使主线程睡眠一段时间
handler.sendEmptyMessage(WAIT_FOR);
setContentView(R.layout.main);
}
private Handler handler = new Handler() {
public voidhandleMessage(Message msg) {
if (msg.what == WAIT_FOR) {
try {
//主线程睡眠一段时间
Thread.sleep(5000);
} catch(InterruptedException e) {
// TODO Auto-generatedcatch block
e.printStackTrace();
}
}
}
};
}
