安卓歡迎界面製作

在開發android的應用當中,歡迎界面一般採用全屏顯示,有兩種實現的方法。其一是在Java代碼中實現,其二是在配置文件中實現。

1. 在Java代碼中設置

super.onCreate(savedInstanceState);  

requestWindowFeature(Window.FEATURE_NO_TITLE);  //無title  

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  

              WindowManager.LayoutParams.FLAG_FULLSCREEN);  //全屏  

setContentView(R.layout.main);  

在這裏需要注意的是這兩段Java代碼必須放在setContentView( )之前,不然會報錯,錯誤顯示如下。

Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content  

2. 在Manifest文件中修改

默認啓動的Activity里加 android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 即可。

Java代碼中加入如下代碼:

new Handler().postDelayed(new Runnable()

                  {

                          publicvoid run()

                          {

                                   //TODO Auto-generated method stub

                                   Intentintent = new Intent();

                                   intent.setClass(WelcomeActivity.this,BackgroundActivity.class);

                                   WelcomeActivity.this.startActivity(intent);

                                   WelcomeActivity.this.finish();

                          }      

                  },500);

有耗時操作時,開闢子線程配合主線程管理UI。

Handler的定義:主要接受子線程發送的數據, 並用此數據配合主線程更新UI。


ps:

<!-- 編輯框顯示android:background="@android:drawable/editbox_background_normal"-->

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章