当前位置:网站首页>A full screen gesture adaptation scheme
A full screen gesture adaptation scheme
2022-06-29 01:34:00 【Rapeseed classmate】
Someone else's code copied online , I can't find the original , So it can only be marked as original , What the original author saw , Please contact me , I posted the original link
The reason for pasting here is that I'm afraid I won't find such an excellent scheme in the future
Here is the complete code :
package com.yangcong345.support.base.utils;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
/**
* Time :2022/6/21 14:53
* author : Rapeseed
* remarks : The method used to get the virtual navigation bar
*/
public class NavigationBarUtil {
/**
* Get the height of the virtual key
* If the full screen is enabled , Then return to 0
* If the navigation bar is hidden , Then return to 0
* Return system value
*/
public static int getNavigationBarHeight(Context context) {
if (isFullScreenEnable(context)) {
return 0;
}
if (isNavigationBarHide(context)) {
return 0;
}
return getNavigationBarHeightInner(context);
}
/**
* Whether the full screen gesture is enabled
*/
public static boolean isFullScreenEnable(Context context) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
return Settings.Global.getInt(context.getContentResolver(), getDeviceInfo(), 0) != 0;
}
return false;
}
/**
* Get device information ( Currently, it supports several mainstream full screen mobile phones , Test Huawei 、 millet 、oppo、 meizu 、vivo Fine )
*/
private static String getDeviceInfo() {
String brand = Build.BRAND;
if (TextUtils.isEmpty(brand)) return "navigationbar_is_min";
if (brand.equalsIgnoreCase("HUAWEI")) {
return "navigationbar_is_min";
} else if (brand.equalsIgnoreCase("XIAOMI")) {
return "force_fsg_nav_bar";
} else if (brand.equalsIgnoreCase("VIVO")) {
return "navigation_gesture_on";
} else if (brand.equalsIgnoreCase("OPPO")) {
return "navigation_gesture_on";
} else {
return "navigationbar_is_min";
}
}
/**
* Whether the virtual navigation bar is hidden , This method needs a delay to get
*/
private static boolean isNavigationBarHide(Context context) {
if (!(context instanceof Activity)) return false;
Activity activity = (Activity) context;
View view = activity.findViewById(android.R.id.navigationBarBackground);
if (view == null) return true;
return view.getVisibility() != View.VISIBLE;
}
/**
* Virtual key height ( Whether hidden or not )
*/
private static int getNavigationBarHeightInner(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
public static void hideNavigationBar(Window window) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
int option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
window.getDecorView().setSystemUiVisibility(option);
}
}
/**
* To fit the height of the navigation bar
* <p>
* Be careful : This place can't take the original paddingBottom Plus the height of the navigation bar
* reason : The user can change it to the form of sideslip or three King Kong in the system settings
* So we need to be able to activity Of resume Inside to realize adaptation ,
* If the paddingBottom + NavigationBarHeight In the form of
* It will cause the spacing at the bottom to become larger and larger
*
* @param rootView: Page and layout , After passing in the page and layout , A navigation bar will be added by default padding
*/
public static void adapterNavigationBar(final View rootView) {
rootView.post(() -> {
int height = getNavigationBarHeight(rootView.getContext());
rootView.setPadding(0, 0, 0, height);
});
}
}
边栏推荐
- TypeScript(5)类、继承、多态
- Connected to rainwater series problems
- To the interface problems we have encountered
- Battle drag method 1: moderately optimistic and build self-confidence (2)
- SAP ui5 beginner tutorial 24 - how to use OData data model
- AHA C language, C language programming introductory books and PPT (PDF version) download website
- 7-29 delete substring in string (non KMP)
- [RRT 3D path planning] rapid expansion of random tree UAV 3D path planning based on MATLAB [including Matlab source code phase 1914]
- 数据库-优化器
- Basic use of Sqlalchemy
猜你喜欢

Werewolf kill casual game wechat applet template source code / wechat game source code

Rasa dialogue robot helpdesk (V)

机构加密资产产品上周流出4.23亿美元资金,创历史新高

致我们曾经遇到过的接口问题

立创eda学习笔记:铺铜死区?孤岛?死铜?

Large-scale case applications to developing post-click conversion rate estimation with MTL

测试只能干到35岁?35岁+的测试就会失业?

Day 7 scripts and special effects

TypeScript(6)函数

Learning notes of Lichuang EDA: Copper laying dead zone? isolated island? Dead copper?
随机推荐
Connected to rainwater series problems
SAP ui5 beginner tutorial Part 23 - sorting sort and grouping Group trial version of list control
Statistical learning method (3/22) k-nearest neighbor method
Large-scale case applications to developing post-click conversion rate estimation with MTL
Pytorch -- use and modification of existing network model
肖特基二极管在防止电源反接的作用
Analysis of parsing principle of OData metadata request response in SAP ui5 application
Statistical learning method (4/22) naive Bayes
Advanced installer architect authoring tool
Typescript (6) function
NOIP2006-2018 提高组 初赛试题完善程序题 CSP-S 2019 2020 初赛试题完善程序题
Statistical learning method (2/22) perceptron
802.1x协议简述
统计学习方法(3/22)K近邻法
MySQL realizes data comparison between two tables by calculating intersection and difference sets
多维分析预汇总应该怎样做才管用?
Database - optimizer
【内网穿透】Frp 自建跳板-两个内网通讯上线-反弹shell
What is the difference between the history and Western blotting
4276. 擅长C