您的位置:首页 > 移动开发 > Android开发

android 隐藏状态栏,全屏,背景模糊,不能横屏

2015-07-29 22:54 399 查看
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"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息