status bar使用

来源:互联网 发布:mysql 5.17 ngram 编辑:程序博客网 时间:2024/06/14 19:49

一、设置状态栏
1、This lesson describes how to dim the system bars (that is, the status and the navigation bars) on Android 4.0 (API level 14) and higher. Android does not provide a built-in way to dim the system bars on earlier versions.
**覆盖状态栏

        setContentView(R.layout.activity_main);        View decorView = getWindow().getDecorView();        int uiOptions = View.SYSTEM_UI_FLAG_LOW_PROFILE;//This is for use in games, book readers, video players, or any other        decorView.setSystemUiVisibility(uiOptions);

看一下状态栏对比
这里写图片描述

这里写图片描述

显示状态栏 :切换的试下显示

  View decorView = getActivity().getWindow().getDecorView();// Calling setSystemUiVisibility() with a value of 0 clears// all flags.  decorView.setSystemUiVisibility(0);

参考: https://developer.android.com/training/system-ui/dim.html

二、Hiding the Status Bar
Hide the Status Bar on Android 4.0 and Lower

public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        // If the Android version is lower than Jellybean, use this call to hide        // the status bar.        if (Build.VERSION.SDK_INT < 16) {            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                    WindowManager.LayoutParams.FLAG_FULLSCREEN);        }        setContentView(R.layout.activity_main);    }    ...}

在2.3的模拟器上的效果
这里写图片描述
还有一种方式 设置style,一跑就崩溃

Hide the Status Bar on Android 4.1 and Higher

View decorView = getWindow().getDecorView();// Hide the status bar.int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;decorView.setSystemUiVisibility(uiOptions);// Remember that you should never show the action bar if the// status bar is hidden, so hide that too if necessary.ActionBar actionBar = getActionBar();actionBar.hide();

这里写图片描述

0 0