永久全屏Android应用程序

时间:2016-05-28 23:24:24

标签: android fullscreen

我有一个全屏应用程序,但是当我显示一个弹出窗口时,我失去了全屏幕行为,我只是在弹出的时候我的应用程序只是丢失了全屏,

这是我的全屏方法:

   public void call(Activity activity) {
    if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
        View v = activity.getWindow().getDecorView();
        v.setSystemUiVisibility(View.GONE);
    } else if(Build.VERSION.SDK_INT >= 19) {
        //for new api versions.
        View decorView = activity.getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(uiOptions);
    }
}

我谷歌它,我发现在post&#34; 只有当您调用它的视图可见时才有效&#34;

那么解决方案呢?

3 个答案:

答案 0 :(得分:0)

试试这个:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main);

}

更新: 试试这个:

public void open(View view){

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setMessage("Are you sure,You wanted to make decision");



    alertDialogBuilder.setPositiveButton("yes", new DialogInterface.OnClickListener() {

       @Override
       public void onClick(DialogInterface arg0, int arg1) {
          Toast.makeText(MainActivity.this,"You clicked yes button",Toast.LENGTH_LONG).show();
       }
    });

    alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
       @Override
       public void onClick(DialogInterface dialog, int which) {
          finish();
       }
    });

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
    alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    alertDialog.getWindow().getDecorView().setSystemUiVisibility(
              View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
              | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
          | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
          | View.SYSTEM_UI_FLAG_FULLSCREEN
          | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
          | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);


    alertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

 }

答案 1 :(得分:0)

在这种情况下您必须使用SYSTEM_UI_FLAG_IMMERSIVE_STICKY,有关详细信息,请参阅官方documentation

<强>更新

不要忘记添加manifest.xml这个

<activity android:name=".YourActivity" 
   android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
      />

答案 2 :(得分:0)

这需要在 onWindowFocusChanged 完成,因为弹出窗口改变了窗口焦点。我是这样做的:

override fun onWindowFocusChanged(hasFocus: Boolean) {
    super.onWindowFocusChanged(hasFocus)
    if (hasFocus && MyPref.getPref(PREF_FULLSCREEN, true)) {
        fullscreen()
    }
}