android:fix navbar setHidden cause bottombar translucent

This commit is contained in:
pengfei.zhou 2020-02-27 18:38:44 +08:00 committed by osborn
parent 56f21f32cc
commit e11a26bd6d
3 changed files with 152 additions and 134 deletions

View File

@ -29,7 +29,7 @@ android {
} }
afterEvaluate { afterEvaluate {
//buildJSBundle.exec() buildJSBundle.exec()
} }
task buildJSBundle(type: Exec) { task buildJSBundle(type: Exec) {

View File

@ -25,6 +25,7 @@ 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.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.TextView; import android.widget.TextView;
@ -32,7 +33,6 @@ 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;
@ -88,15 +88,27 @@ 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(); Activity activity = (Activity) getContext();
Window window = activity.getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (b) { if (b) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); window.getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().setStatusBarColor(Color.TRANSPARENT); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
} }
} else { } else {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); int visibility = window.getDecorView().getSystemUiVisibility();
visibility = visibility ^ (SYSTEM_UI_FLAG_LAYOUT_STABLE | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
window.getDecorView().setSystemUiVisibility(visibility);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
} }
} }
} }

View File

@ -6,133 +6,139 @@ const shareIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAMAAAD
@Entry @Entry
class NavbarDemo extends Panel { class NavbarDemo extends Panel {
build(rootView: Group): void { build(rootView: Group): void {
scroller(vlayout([ scroller(
title("Navbar Demo"), vlayout(
label('isHidden').apply({ [
width: 200, title("Navbar Demo"),
height: 50, label('isHidden').apply({
backgroundColor: colors[0], width: 200,
textSize: 30, height: 50,
textColor: Color.WHITE, backgroundColor: colors[0],
layoutConfig: layoutConfig().just(), textSize: 30,
onClick: () => { textColor: Color.WHITE,
navbar(context).isHidden().then(e => modal(context).alert(`Navbar isHidden:${e}`)).catch(e => { layoutConfig: layoutConfig().just(),
modal(context).alert(e) onClick: () => {
}) navbar(context).isHidden().then(e => modal(context).alert(`Navbar isHidden:${e}`)).catch(e => {
} modal(context).alert(e)
} as IText), })
label('setHidden').apply({ }
width: 200, } as IText),
height: 50, label('setHidden').apply({
backgroundColor: colors[0], width: 200,
textSize: 30, height: 50,
textColor: Color.WHITE, backgroundColor: colors[0],
layoutConfig: layoutConfig().just(), textSize: 30,
onClick: () => { textColor: Color.WHITE,
navbar(context).isHidden() layoutConfig: layoutConfig().just(),
.then(e => navbar(context).setHidden(!e)) onClick: () => {
.catch(e => { navbar(context).isHidden()
modal(context).alert(e) .then(e => navbar(context).setHidden(!e))
}) .catch(e => {
} modal(context).alert(e)
} as IText), })
label('setTitle').apply({ }
width: 200, } as IText),
height: 50, label('setTitle').apply({
backgroundColor: colors[0], width: 200,
textSize: 30, height: 50,
textColor: Color.WHITE, backgroundColor: colors[0],
layoutConfig: layoutConfig().just(), textSize: 30,
onClick: () => { textColor: Color.WHITE,
navbar(context).setTitle('Setted Title') layoutConfig: layoutConfig().just(),
.catch(e => { onClick: () => {
modal(context).alert(e) navbar(context).setTitle('Setted Title')
}) .catch(e => {
} modal(context).alert(e)
} as IText), })
label('setBgColor').apply({ }
width: 200, } as IText),
height: 50, label('setBgColor').apply({
backgroundColor: colors[0], width: 200,
textSize: 30, height: 50,
textColor: Color.WHITE, backgroundColor: colors[0],
layoutConfig: layoutConfig().just(), textSize: 30,
onClick: () => { textColor: Color.WHITE,
navbar(context).setBgColor(Color.YELLOW) layoutConfig: layoutConfig().just(),
.catch(e => { onClick: () => {
modal(context).alert(e) navbar(context).setBgColor(Color.YELLOW)
}) .catch(e => {
} modal(context).alert(e)
} as IText), })
label('setLeft').apply({ }
width: 200, } as IText),
height: 50, label('setLeft').apply({
backgroundColor: colors[0], width: 200,
textSize: 30, height: 50,
textColor: Color.WHITE, backgroundColor: colors[0],
layoutConfig: layoutConfig().just(), textSize: 30,
onClick: () => { textColor: Color.WHITE,
navbar(context).setLeft(text({ layoutConfig: layoutConfig().just(),
width: 70, onClick: () => {
height: 44, navbar(context).setLeft(text({
textColor: Color.BLACK, width: 70,
layoutConfig: layoutConfig().just().configAlignment(Gravity.Center), height: 44,
text: "Left", textColor: Color.BLACK,
})) layoutConfig: layoutConfig().just().configAlignment(Gravity.Center),
.catch(e => { text: "Left",
modal(context).alert(e) }))
}) .catch(e => {
} modal(context).alert(e)
} as IText), })
label('setRight').apply({ }
width: 200, } as IText),
height: 50, label('setRight').apply({
backgroundColor: colors[0], width: 200,
textSize: 30, height: 50,
textColor: Color.WHITE, backgroundColor: colors[0],
layoutConfig: layoutConfig().just(), textSize: 30,
onClick: () => { textColor: Color.WHITE,
navbar(context).setRight(hlayout([ layoutConfig: layoutConfig().just(),
text({ onClick: () => {
width: 70, navbar(context).setRight(hlayout([
height: 44, text({
textColor: Color.BLACK, width: 70,
layoutConfig: layoutConfig().just().configAlignment(Gravity.Center), height: 44,
text: "Right", textColor: Color.BLACK,
}), layoutConfig: layoutConfig().just().configAlignment(Gravity.Center),
image({ text: "Right",
imageBase64: shareIcon }),
}).apply({ image({
layoutConfig: layoutConfig().just().configAlignment(gravity().centerY()), imageBase64: shareIcon
width: 33, }).apply({
height: 33, layoutConfig: layoutConfig().just().configAlignment(gravity().centerY()),
onClick: () => { width: 33,
modal(context).toast('Right Clicked', Gravity.Bottom) height: 33,
} onClick: () => {
}) modal(context).toast('Right Clicked', Gravity.Bottom)
])) }
.catch(e => { })
modal(context).alert(e) ]))
}) .catch(e => {
} modal(context).alert(e)
} as IText), })
label('Pop').apply({ }
width: 200, } as IText),
height: 50, label('Pop').apply({
backgroundColor: colors[0], width: 200,
textSize: 30, height: 50,
textColor: Color.WHITE, backgroundColor: colors[0],
layoutConfig: layoutConfig().just(), textSize: 30,
onClick: () => { textColor: Color.WHITE,
navigator(context).pop() layoutConfig: layoutConfig().just(),
} onClick: () => {
} as IText), navigator(context).pop()
]).apply({ }
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT), } as IText),
gravity: gravity().center(), ],
space: 10, {
} as IVLayout)).apply({ layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT),
layoutConfig: layoutConfig().most(), gravity: gravity().center(),
}).in(rootView) space: 10,
}),
{
layoutConfig: layoutConfig().most(),
backgroundColor: Color.BLUE,
}
).in(rootView)
} }
} }