优化:WebViewActivity.java 兼容三按键导航栏

This commit is contained in:
zlzw 2022-12-06 16:58:30 +08:00
parent 9ead9a6fb8
commit 29ddc68870
2 changed files with 23 additions and 5 deletions

View File

@ -73,7 +73,7 @@ public class WebViewActivity extends AbsActivity {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.topMargin = DpUtil.dp2px(1); params.topMargin = DpUtil.dp2px(1);
// mWebView.setLayoutParams(params); // mWebView.setLayoutParams(params);
//mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER); //mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER);
mWebView.setWebViewClient(new WebViewClient() { mWebView.setWebViewClient(new WebViewClient() {
@Override @Override
@ -96,9 +96,11 @@ public class WebViewActivity extends AbsActivity {
if (url.contains("for")) { if (url.contains("for")) {
mWebView.loadUrl("javascript:goAnchorTab()"); mWebView.loadUrl("javascript:goAnchorTab()");
} }
//屏幕高度-ft_title的paddingTop //真实屏幕高度-(ft_title的高度+导航栏高度)
int height = DeviceUtils.getScreenHeight(mContext)-DpUtil.dp2px(24); int height = DeviceUtils.getScreenRealHeight(mContext) - DpUtil.dp2px(72) - getCurrentNavigationBarHeight(mContext);
view.loadUrl("javascript:window.androidObject.setHeight("+height+",0,false)"); if (!navigationGestureEnabled(mContext)) {
view.loadUrl("javascript:window.androidObject.setHeight(" + height + ",0,false)");
}
} }
}); });

View File

@ -5,8 +5,10 @@ import android.app.ActivityManager;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Point;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.WindowManager;
/** /**
* 设备通用类 * 设备通用类
@ -36,6 +38,19 @@ public class DeviceUtils {
return displayMetrics.heightPixels; return displayMetrics.heightPixels;
} }
/**
* 获取屏幕真实高度
*
* @param activity activity
* @return 屏幕高度
*/
public static int getScreenRealHeight(Activity activity) {
WindowManager service = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
Point point = new Point();
service.getDefaultDisplay().getRealSize(point);
return point.y;
}
/** /**
* 根据手机的分辨率从 dp 的单位 转成为 px(像素) * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
* *
@ -63,7 +78,7 @@ public class DeviceUtils {
public static String getVersionName(Context context) { public static String getVersionName(Context context) {
try { try {
PackageManager manager = context.getPackageManager(); PackageManager manager = context.getPackageManager();
PackageInfo info = manager.getPackageInfo(context.getPackageName(),0); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
return info.versionName; return info.versionName;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -81,6 +96,7 @@ public class DeviceUtils {
am.getMemoryInfo(mi); am.getMemoryInfo(mi);
return mi.lowMemory; return mi.lowMemory;
} }
public static String getMemory(Context context) { public static String getMemory(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();