UniApp develops Android full screen to make the bottom navigation bar transparent

When using UniApp to develop Android programs, the bottom navigation bar of a full-screen mobile phone is not transparent by default, but has a colored background. Generally set to the same color as the background color, pretending it is transparent.

As can be seen from the above figure, the background of the NavigationBar at the bottom is white, and the contrast with the gray background in the middle is quite obvious. There is not much content on this kind of page, and it will not reach the bottom, or will the TabBar at the bottom affect the use very much.

But when there is a lot of content on the page, it will look very strange if it can exceed the bottom, and its background will cover the content of the page. So I want to set it to be completely transparent.

The code for setting transparency is as follows:

if(uni.getSystemInfoSync().platform === 'android'){
	var Color = plus.android.importClass("android.graphics.Color");   
	var WindowManager = plus.android.importClass("android.view.WindowManager");
	var Build = plus.android.importClass("android.os.Build");
	plus.android.importClass("android.view.Window");
	var mainActivity = plus.android.runtimeMainActivity();
	var window_android = mainActivity.getWindow();
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
		window_android.setNavigationBarContrastEnforced(false);
	}
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		window_android.setNavigationBarColor(Color.TRANSPARENT);
	}
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		if ((window_android.getAttributes().flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0) {
		    window_android.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
		}
	}
}

 Calling Native.js is implemented using native code. Just set it up.

Guess you like

Origin blog.csdn.net/wangmy1988/article/details/130295667