问题
I'm making a custom lock screen.
The lock screen is an activity which I launch by the time the screen goes off.
However, I can't make the activity be both transparent & fullscreen.
The Status bar keeps showing.
Here's what I do in the manifest:
<activity android:name=".activities.LockScreenActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
I'm also adding these extras in activit's onCreate:
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.lock_screen);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
But it can't seem to work :|
why?
回答1:
delete the code from onCreate(). use this in Manifestfile.
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
otherwise create the theme according to your requirement.
回答2:
You Need to set flags before setContentView, it should work fine then
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.lock_screen);
回答3:
Here is it link (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();
Hide the Status Bar on Android 4.0 and Lower:
<application
...
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>
@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);
}
来源:https://stackoverflow.com/questions/8623605/full-screen-transparent-activity-no-title-status-bar-doesnt-work-why