简体   繁体   中英

Android Can we hide status bar when onAttachedToWindow() is called?

There is a way to hide the status bar or disable it when the onAttachedToWindow is called and window type is keyguard ?? I have tried this on my activity class:

and this is onCreate

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setWindowAnimations(0);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_lock); 
}

public void onAttachedToWindow() {
    super.onAttachedToWindow();
    getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

and this in my manifest

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

but sometimes the status bar disappears, and other times it appears.

If i try this:

public void onAttachedToWindow() {
    super.onAttachedToWindow();
    getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

it gives me the error:

12-22 11:03:51.209: E/AndroidRuntime(9088): android.util.AndroidRuntimeException: requestFeature() must be called before adding content

Ok, before you can hide the status bar programmatically you have to request the feature:

requestWindowFeature(Window.FEATURE_NO_TITLE);

And then to request the fullscreen you can just use:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM