Android Fullscreen Not Working: Gingerbread

谁说胖子不能爱 提交于 2019-12-11 15:09:23

问题


I am trying to make a fullscreen activity, but it doesn't seem to work in GingerBread, here is my code

 @SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_eyes);
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
    ActionBar actionBar = getActionBar();
    actionBar.hide();

}

   if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD){
       requestWindowFeature(Window.FEATURE_NO_TITLE);
       getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
   }

In Gingerbread there is still a title.

Does anyone know how to fix this?


回答1:


First of all you should set the activity as full screen in the manifest. In the desired activity, add this code

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

and your onCreate should be like this

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD){
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

setContentView(R.layout.main);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
    ActionBar actionBar = getActionBar();
    actionBar.hide();

}

This might solve the problem.




回答2:


Remember that you must call requestWindowFeature before call setContentView

Try this to make a full screen activity by java:

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

and in Manifest

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



回答3:


requestWindowFeature has to be called before super.onCreate. Like so:

@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD){
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_eyes);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
        ActionBar actionBar = getActionBar();
        actionBar.hide();
    }

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD){
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    // ...

If this doesn't work, move the getWindow().setFlags(...) call to the top as well.




回答4:


Unless you have a reason to not setting it in your manifest, add this attribute to your tag in the Manifest:

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

And I believe you wouldn't need the if-conditions code in the onCreate().




回答5:


isn't just android:theme ="@android:style/Theme.NoTitleBar.Fullscreen" both hides the titlebar and the notification area?

it equals to:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);

I learn this from https://github.com/pocorall/scaloid-apidemos/blob/master/src/main/java/com/example/android/apis/graphics/CameraPreview.java



来源:https://stackoverflow.com/questions/12127354/android-fullscreen-not-working-gingerbread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!