0

我正在尝试进行全屏活动,但它似乎在 GingerBread 中不起作用,这是我的代码

 @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);
   }

在姜饼中仍然有一个标题。

有谁知道如何解决这一问题?

4

5 回答 5

3

首先,您应该在清单中将活动设置为全屏。在所需的活动中,添加此代码

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

你的 onCreate 应该是这样的

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();

}

这可能会解决问题。

于 2012-08-26T04:05:28.380 回答
3

请记住,您必须先打电话requestWindowFeature再打电话setContentView

试试这个通过java进行全屏活动:

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

并在清单中

android:theme="@android:style/Theme.Translucent.NoTitleBar"
于 2012-08-26T04:30:20.583 回答
1

requestWindowFeature必须在之前调用super.onCreate。像这样:

@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);
    }
    // ...

如果这不起作用,请将getWindow().setFlags(...)调用也移到顶部。

于 2012-08-26T03:30:37.617 回答
0

是不是android:theme ="@android:style/Theme.NoTitleBar.Fullscreen"既隐藏了标题栏又隐藏了通知区域?

它等于:

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

我从https://github.com/pocorall/scaloid-apidemos/blob/master/src/main/java/com/example/android/apis/graphics/CameraPreview.java了解到这一点

于 2013-09-18T02:39:20.330 回答
0

除非您有理由不在清单中设置它,否则请将此属性添加到清单中的标记中:

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

而且我相信您不需要onCreate().

于 2012-08-26T08:11:02.420 回答