16

这是我的代码:

params = new WindowManager.LayoutParams(
    WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
    PixelFormat.TRANSLUCENT);

wm = (WindowManager) getApplicationContext()
    .getSystemService(Context.WINDOW_SERVICE);

inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mTopView = (ViewGroup) inflater.inflate(R.layout.activity_invisible, null);

params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
    | WindowManager.LayoutParams.FLAG_DIM_BEHIND
    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
    | WindowManager.LayoutParams.FLAG_FULLSCREEN;

if (keep==true) {
    int value = brightnessIntent.getExtras().getInt("value");
    float v=value/255.0f;
    params.dimAmount=0;
    params.alpha=v;
    rl = (RelativeLayout) mTopView.findViewById(R.id.window);

    getWindow().setAttributes(params);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    wm.addView(mTopView, params);
}

视图仍然显示状态栏,mTopView是一个覆盖窗口。如何让覆盖窗口覆盖整个屏幕?我不想“隐藏”状态栏,我希望我的活动覆盖在它上面。

[编辑] 强调文本 我已经在我的onCreate()方法中有这个:

requestWindowFeature(Window.FEATURE_NO_TITLE); 
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

我的清单定义了一种全屏风格。

截图

在此处输入图像描述

这就是目前的情况,我希望覆盖也扩展到状态栏。

4

6 回答 6

18

我所要做的就是这个

params.flags=WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN| and the rest

这将覆盖视图扩展到状态栏。

于 2013-01-18T12:36:22.023 回答
6

此代码来自“Android Application 4 Development”。你必须处理不同的安卓版本

 // Hiding the Action Bar for different android versions 
    if (Build.VERSION.SDK_INT < 16) {
        // Hide the Action Bar on Android 4.0 and Lower
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
     }else {
        // Hide the Action Bar on Android 4.1 and Higher
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
        android.app.ActionBar actionBar = getActionBar();
        actionBar.hide();
     }
于 2014-08-30T23:08:43.007 回答
3

您可以使用两种方式隐藏状态栏:

1)在您的活动onCreate()方法中定义以下行。

  requestWindowFeature(Window.FEATURE_NO_TITLE);

2)在应用程序级别定义主题,不通过应用程序显示状态栏,如下所示:

<application android:label="@string/app_name"
  android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
于 2013-01-18T11:44:37.260 回答
0

尝试这个..

   requestWindowFeature(Window.FEATURE_NO_TITLE);

它不会隐藏您的状态栏,您的应用程序将覆盖全屏,只有状态栏可见

           public class example extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);


    setContentView(R.layout.example);
}

}

并隐藏状态栏

您可以使用

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

试试这个方法

final WindowManager.LayoutParams params = new WindowManager.LayoutParams( 
WindowManager.LayoutParams.FLAG_FULLSCREEN, 
WindowManager.LayoutParams.FLAG_FULLSCREEN,                 
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,               
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
            PixelFormat.TRANSLUCENT);   

    WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);    

    ViewGroup mTopView = (ViewGroup) App.inflater.inflate(R.layout.main, null);
    getWindow().setAttributes(params);
    wm.addView(mTopView, params);
于 2013-01-18T11:39:09.360 回答
0

要在 Android 中创建始终处于顶部的全屏覆盖活动:

public void onCreate(Bundle savedInstanceState) {       
 super.onCreate(savedInstanceState);        

 requestWindowFeature(Window.FEATURE_NO_TITLE);
 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
 getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);             
 getWindow().setBackgroundDrawableResource(android.R.color.transparent);
 getWindow().setFormat(PixelFormat.TRANSLUCENT);
 setContentView(R.layout.main);
 }

必须在 xml 清单中从外部启用半透明设置,否则它也不起作用。

 <item name="android:windowIsTranslucent">true</item>
于 2016-04-20T16:48:48.530 回答
-1

您可以使用以下方法隐藏标题栏:

public class MainActivity extends AppCompatActivity {  
@Override  
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    requestWindowFeature(Window.FEATURE_NO_TITLE);  
    getSupportActionBar().hide(); 
    setContentView(R.layout.activity_main);  
  }  
}  

并使用以下方法获取全屏:

public class MainActivity extends AppCompatActivity {  
@Override  
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.activity_main);   
   }  
 }  

你也可以在styles.xml中使用parent="Theme.AppCompat.NoActionBar"

于 2018-07-31T13:03:52.607 回答