在Android中隐藏底部系统栏-Ionic V4

时间:2018-12-31 08:38:49

标签: ionic-framework ionic3

我遇到一个有关底部系统栏的问题,如果该栏的状态易于隐藏,而底部栏却不容易隐藏,我尝试 hideFormAccessoryBar,但没有帮助

1 个答案:

答案 0 :(得分:0)

这花了我一些时间,但我设法找到了解决方案。事实证明,这部分用户界面称为“导航栏”。您可以在SYSTEM_UI_FLAG_HIDE_NAVIGATION文件中设置一个视图值MainActivity.java来将其隐藏。官方文档在这里,

https://developer.android.com/training/system-ui/navigation#java

IljaDaderko提供了有关如何在此处https://github.com/ionic-team/capacitor/issues/2423实施该属性的解决方案,并且有ionic的PR代表可以立即使用此属性。

基本上从今天开始,您需要在android文件夹中打开MainActivity.java文件(应在ionic 4、3中的android / app / src / main / java / ...稍有不同)并进行更新文件看起来像这样,

package io.ionic.starter;

import android.os.Bundle;
import android.view.View;

import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Plugin;

import java.util.ArrayList;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    hideSystemUI();

    /**
    * Initialize capacitor bridge
    */
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      // Additional plugins you've installed go here
      // Ex: add(TotallyAwesomePlugin.class);
    }});
  }

  @Override
  public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
      hideSystemUI();
    }
  }

  /**
  * Hide android navbar and toolbar for full screen experience
  */
  private void hideSystemUI() {
    final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    View decorView = getWindow().getDecorView();

    decorView.setSystemUiVisibility(flags);
    decorView.setOnSystemUiVisibilityChangeListener((int visibility) ->  {
      if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
        decorView.setSystemUiVisibility(flags);
      }
    });
  }
}