diff --git a/doric-android/doric/src/main/java/pub/doric/DoricActivity.java b/doric-android/doric/src/main/java/pub/doric/DoricActivity.java index 12e4f525..266d04e6 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricActivity.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricActivity.java @@ -15,10 +15,7 @@ */ package pub.doric; -import android.os.Build; import android.os.Bundle; -import android.view.View; -import android.view.WindowManager; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; @@ -41,9 +38,5 @@ public class DoricActivity extends AppCompatActivity { .add(R.id.container, doricFragment) .commit(); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); - } - getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN); } } diff --git a/doric-android/doric/src/main/java/pub/doric/plugin/NavBarPlugin.java b/doric-android/doric/src/main/java/pub/doric/plugin/NavBarPlugin.java index 96e0edce..c771df8a 100644 --- a/doric-android/doric/src/main/java/pub/doric/plugin/NavBarPlugin.java +++ b/doric-android/doric/src/main/java/pub/doric/plugin/NavBarPlugin.java @@ -15,8 +15,12 @@ */ package pub.doric.plugin; +import android.os.Build; +import android.view.WindowManager; import android.widget.FrameLayout; +import androidx.appcompat.app.AppCompatActivity; + import com.github.pengfeizhou.jscore.ArchiveException; import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSObject; @@ -68,6 +72,16 @@ public class NavBarPlugin extends DoricJavaPlugin { JSObject jsObject = jsDecoder.decode().asObject(); boolean hidden = jsObject.getProperty("hidden").asBoolean().value(); navBar.setHidden(hidden); + + AppCompatActivity activity = ((AppCompatActivity) getDoricContext().getContext()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (hidden) { + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); + } else { + activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); + } + } + promise.resolve(); } catch (ArchiveException e) { e.printStackTrace(); diff --git a/doric-android/doric/src/main/java/pub/doric/plugin/StatusBarPlugin.java b/doric-android/doric/src/main/java/pub/doric/plugin/StatusBarPlugin.java index d105f812..7c17667a 100644 --- a/doric-android/doric/src/main/java/pub/doric/plugin/StatusBarPlugin.java +++ b/doric-android/doric/src/main/java/pub/doric/plugin/StatusBarPlugin.java @@ -16,6 +16,7 @@ import pub.doric.async.AsyncResult; import pub.doric.extension.bridge.DoricMethod; import pub.doric.extension.bridge.DoricPlugin; import pub.doric.extension.bridge.DoricPromise; +import pub.doric.utils.DoricUtils; import pub.doric.utils.ThreadMode; @DoricPlugin(name = "statusbar") @@ -38,8 +39,10 @@ public class StatusBarPlugin extends DoricJavaPlugin { AppCompatActivity activity = ((AppCompatActivity) getDoricContext().getContext()); View decorView = activity.getWindow().getDecorView(); if (hidden) { + decorView.setPadding(0, DoricUtils.getStatusBarHeight(activity), 0, 0); decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN); } else { + decorView.setPadding(0, 0, 0, 0); decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } currentMode = 0;