我們可以通過requestWindowFeature方法可以設置標題攔是否顯示,通過setFalg()方法可以設置全屏,具體效果如下:
import android.app.Activity; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; public class FullScreen extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 設置無標題攔 requestWindowFeature(Window.FEATURE_NO_TITLE); // 設置為全屏模式 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // 設置為橫屏 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.main); } } |
附加說明:
final boolean | Enable extended window features.(用來附加額外的視窗功能) |
一些常用的應用
1、隱藏標題列
requestWindowFeature(Window.FEATURE_NO_TITLE);
2、在標題列顯示進度條
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.progressbar_1);
setProgressBarVisibility(true);
final ProgressBar progressHorizontal = (ProgressBar)findViewById(R.id.progress_horizontal);
setProgress(progressHorizontal.getProgress() * 100);
setSecondaryProgress(progressHorizontal.getSecondaryProgress()* 100);
3、使用自訂標題列
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.xxx);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.my_title_bar);
(要注意順序)
4、清除標題列內容,而區域保留
((ViewGroup)getWindow().findViewById(com.android.internal.R.id.title_container)).removeAllViews();
5、隱藏標題列
((ViewGroup)getWindow().
findViewById(com.android.internal.R.id.title_container)).setVisibility(View.GONE);
6、顯示標題列
...setVisibility(View.VISIBLE);
其他注意事項
(1) requestWindowFeature()要在setContentView()之前調用;
(2) 設置各種Feature,是具有排它性的,一旦設置,後續不可更改為別的類型;
(3)當使用TabHost(由ActivityGroup派生)時,各個Tab裡的Activity,要麼都是NO_TITLE,要麼都是CUSTOM_TITLE,無法分別進行設置。
設定的屬性有
int | The default features enabled (默認的) | | | | |||||||||||
int | Flag for the context menu. ( 上下文菜單,相當於PC上的右鍵菜單(預設使能) ) | | | ||||||||||||
int | Flag for custom title. (自定義標題攔時使用) | | | ||||||||||||
int | Flag for indeterminate progress (不確定的進度條) | | | ||||||||||||
int | Flag for having an icon on the left side of the title bar (在標題攔左邊有一個icon) | | | ||||||||||||
int | Flag for the "no title" feature, turning off the title at the top of the screen. (無標題攔模式) | | | ||||||||||||
int | Flag for the "options panel" feature. | | | ||||||||||||
int | Flag for the progress indicator feature ( 在標題列上顯示載入進度,例如webview載入網頁時(條狀進度條) ) | | | ||||||||||||
int | Flag for having an icon on the right side of the title bar (在標題攔右邊有一個icon) | | | ||||||||||||
沒有留言:
張貼留言