android:fix StatusBar background color not transparent

This commit is contained in:
pengfei.zhou 2020-02-17 19:58:52 +08:00 committed by osborn
parent 9b3156ada8
commit 251cb7770c
2 changed files with 15 additions and 10 deletions

View File

@ -17,18 +17,22 @@ package pub.doric.navbar;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.text.Layout; import android.text.Layout;
import android.text.StaticLayout; import android.text.StaticLayout;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.AttrRes; import androidx.annotation.AttrRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import pub.doric.R; import pub.doric.R;
@ -84,6 +88,17 @@ public class BaseDoricNavBar extends FrameLayout implements IDoricNavBar {
@Override @Override
public void setHidden(boolean b) { public void setHidden(boolean b) {
setVisibility(b ? GONE : VISIBLE); setVisibility(b ? GONE : VISIBLE);
AppCompatActivity activity = (AppCompatActivity) getContext();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (b) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
}
} else {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
}
} }
@Override @Override

View File

@ -72,16 +72,6 @@ public class NavBarPlugin extends DoricJavaPlugin {
JSObject jsObject = jsDecoder.decode().asObject(); JSObject jsObject = jsDecoder.decode().asObject();
boolean hidden = jsObject.getProperty("hidden").asBoolean().value(); boolean hidden = jsObject.getProperty("hidden").asBoolean().value();
navBar.setHidden(hidden); 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(); promise.resolve();
} catch (ArchiveException e) { } catch (ArchiveException e) {
e.printStackTrace(); e.printStackTrace();