From 25ae11b77d7b724f70f0935b9d6ae31abe54e602 Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Thu, 10 Oct 2024 15:16:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=8F=E7=B1=B3=E6=9F=90?= =?UTF-8?q?=E6=9C=BA=E5=9E=8B=E9=A6=96=E9=A1=B5=E5=BA=95=E9=83=A8=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E6=A0=8Ficon=E5=B1=95=E7=A4=BA=E4=B8=8D=E5=85=A8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/utils/NavigationBarUtils.java | 65 +++++++++++++++++++ .../yunbao/main/activity/MainActivity.java | 3 + 2 files changed, 68 insertions(+) create mode 100644 common/src/main/java/com/yunbao/common/utils/NavigationBarUtils.java diff --git a/common/src/main/java/com/yunbao/common/utils/NavigationBarUtils.java b/common/src/main/java/com/yunbao/common/utils/NavigationBarUtils.java new file mode 100644 index 000000000..ec6f820f3 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/utils/NavigationBarUtils.java @@ -0,0 +1,65 @@ +package com.yunbao.common.utils; + +import android.app.Activity; +import android.content.res.Resources; +import android.os.Build; +import android.view.ViewConfiguration; +import android.view.ViewGroup; +import android.widget.RelativeLayout; + +public class NavigationBarUtils { + + public static boolean hasNavigationBar(Activity activity) { + boolean hasNavigationBar = false; + int resourceId = activity.getResources().getIdentifier("config_showNavigationBar", "bool", "android"); + if (resourceId > 0) { + hasNavigationBar = activity.getResources().getBoolean(resourceId); + } + + try { + hasNavigationBar |= (Boolean) ViewConfiguration.class.getDeclaredMethod("hasNavigationBar").invoke(ViewConfiguration.get(activity)); + } catch (Exception e) { + e.printStackTrace(); + } + + // Fall back on checking the navigation bar height, if available + if (!hasNavigationBar && hasNavBarHeight()) { + hasNavigationBar = true; + } + + return hasNavigationBar; + } + + public static boolean hasNavBarHeight() { + Resources res = Resources.getSystem(); + int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android"); + if (resourceId > 0) { + return res.getDimensionPixelSize(resourceId) > 0; + } + return false; + } + + // 示例:在Activity中使用该方法 + public static boolean checkNavigationBar(Activity activity) { + return hasNavigationBar(activity); + } + + public static int checkBarHeight(Activity activity) { + int result = 0; + Resources resources = activity.getResources(); + int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + if (resourceId > 0) { + result = resources.getDimensionPixelSize(resourceId); + } + return result; + } + + public static void setBarStatus(RelativeLayout rt_main_tab, Activity mContext){ + if("Xiaomi".equals(Build.BRAND)&&"2210132C".equals(Build.MODEL)){ + ViewGroup.LayoutParams params = rt_main_tab.getLayoutParams(); + params.height =params.height+ NavigationBarUtils.checkBarHeight(mContext); + rt_main_tab.setLayoutParams(params); + } + } + +} \ No newline at end of file diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index 778dffba6..41e686738 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -111,6 +111,7 @@ import com.yunbao.common.utils.GiftCacheUtil; import com.yunbao.common.utils.GoogleUtils; import com.yunbao.common.utils.LiveRoomCheckLivePresenter; import com.yunbao.common.utils.LocationUtil; +import com.yunbao.common.utils.NavigationBarUtils; import com.yunbao.common.utils.ProcessResultUtil; import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.utils.SpUtil; @@ -581,6 +582,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene //获取声网Token getSwToken(); initLogUpdate(); + //检测底部导航栏高度 + NavigationBarUtils.setBarStatus(rt_main_tab,mContext); } private void getSwToken() {