天天看點

android 隐藏狀态欄,全屏,背景模糊,不能橫屏

Android 不顯示标題欄和全屏的設定方法

1.在Manifest.xml中設定

不顯示标題欄

android:theme="@android:style/Theme.NoTitleBar"

全屏

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

2.在代碼中實作

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
           

Android應用開發界面頂部上有灰條,用來顯示項目名稱。這個應用名稱是可以更改的,在strings.xml中,就可以設定 <string name="app_name">應用名稱</string>。如果不顯示的話,加上一個語句就行了:requestWindowFeature(Window.FEATURE_NO_TITLE);

        經過實踐操作具體添加位置:

        public void onCreate(Bundle savedInstanceState) {

                super.onCreate(savedInstanceState);

                requestWindowFeature(Window.FEATURE_NO_TITLE);// 填充标題欄

                setContentView(R.layout.main);

        requestWindowFeature();

       這句需要在setContentView之前使用才能生效。

3

public void fullScreenChange() {

SharedPreferences mPreferences = PreferenceManager

.getDefaultSharedPreferences(this);

boolean fullScreen = mPreferences.getBoolean("fullScreen", false);

WindowManager.LayoutParams attrs = getWindow().getAttributes();

System.out.println("fullScreen的值:" + fullScreen);

if (fullScreen) {

attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);

getWindow().setAttributes(attrs);

// 取消全屏設定

getWindow().clearFlags(

WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

mPreferences.edit().putBoolean("fullScreen", false).commit();

} else {

attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;

getWindow().setAttributes(attrs);

getWindow().addFlags(

WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

mPreferences.edit().putBoolean("fullScreen", true).commit();

}

}

不能橫屏,在AndroidMainFest.aml中添加Activity定義的時候

            android:name="com.example.testcontextmenu.Test_Contextmenu"

            android:configChanges="orientation|keyboardHidden|screenSize"

            android:label="@string/app_name"

            android:screenOrientation="portrait"