Android 8刘海屏特性,Android 8.0刘海屏适配方案 小米和华为根据官方api即可获取隐藏显示转态,oppo和Vivo没有公开API...

/**

* @return 判断Android O的刘海屏

*/

private boolean hasNotchInScreen() {

boolean ret_all = false;

ret_huawei = false;

ret_oppo = false;

ret_vivo = false;

ret_xiaomi = false;

// ---------------------------------------------------------------

// -------------------------- -----------------------

// 华为

// -------------------------- -----------------------

// ---------------------------------------------------------------

try {

ClassLoader cl = content.getClassLoader();

Class HwNotchSizeUtil = cl.loadClass("com.huawei.android.util.HwNotchSizeUtil");

Method get = HwNotchSizeUtil.getMethod("hasNotchInScreen");

ret_huawei = (boolean) get.invoke(HwNotchSizeUtil);

} catch (Exception e) {

}

// ---------------------------------------------------------------

// -------------------------- -----------------------

// oppo

// -------------------------- -----------------------

// ---------------------------------------------------------------

try {

ret_oppo = getPackageManager().hasSystemFeature("com.oppo.feature.screen.heteromorphism");

} catch (Exception e) {

}

// ---------------------------------------------------------------

// -------------------------- -----------------------

// vivo

// -------------------------- -----------------------

// ---------------------------------------------------------------

try {

int NOTCH_IN_SCREEN_VOIO = 0x00000020;//是否有凹槽

ClassLoader cl = content.getClassLoader();

Class FtFeature = cl.loadClass("android.util.FtFeature");

Method get = FtFeature.getMethod("isFeatureSupport", int.class);

ret_vivo = (boolean) get.invoke(FtFeature, NOTCH_IN_SCREEN_VOIO);

} catch (Exception e) {

}

// ---------------------------------------------------------------

// -------------------------- -----------------------

// 小米

// -------------------------- -----------------------

// ---------------------------------------------------------------

try {

String key = "ro.miui.notch";

ClassLoader cl = content.getClassLoader();

Class SystemProperties = cl.loadClass("android.os.SystemProperties");

//参数类型

Class[] paramTypes = new Class[2];

paramTypes[0] = String.class;

paramTypes[1] = int.class;

Method getInt = SystemProperties.getMethod("getInt", paramTypes);

//参数

Object[] params = new Object[2];

params[0] = new String(key);

params[1] = new Integer(0);

ret_xiaomi = (Integer) getInt.invoke(SystemProperties, params) == 1;

} catch (Exception e) {

}

System.out.println("--ret_huawei--:" + ret_huawei);

System.out.println("--ret_oppo--:" + ret_oppo);

System.out.println("--ret_vivo--:" + ret_vivo);

System.out.println("--ret_xiaomi--:" + ret_xiaomi);

Log.i("zhangyb", "hasNotchInScreen: " + ret_oppo);

ret_all = ret_huawei | ret_oppo | ret_vivo | ret_xiaomi;

return ret_all;

}

/**

* 隐藏虚拟导航栏

*/

private void dealSystemUI() {

View view = getWindow().getDecorView();

view.setSystemUiVisibility(

View.SYSTEM_UI_FLAG_LAYOUT_STABLE

| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

| View.SYSTEM_UI_FLAG_FULLSCREEN

| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

}

/**

* 在onResum中调用

*获取参数

* @param view 充满屏幕的view

*/

private void getViewHigh(final View view) {

view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

@Override

public void onGlobalLayout() {

view.getViewTreeObserver().removeOnGlobalLayoutListener(this);

if (ret_oppo || ret_vivo) {

changeNotchHight(getNotchStatus(view));

}

}

});

}

/**

* vivo和oppo的控制

*

* @param view

*/

private int getNotchStatus(View view) {

int notchHight = 0;

int viewH = view.getHeight();

Point point = new Point();

getWindowManager().getDefaultDisplay().getRealSize(point);

int maxH = point.y;

if (viewH == maxH) {

} else {

notchHight = maxH - viewH;

}

return notchHight;

}

/**

* @param hight oppo和vivo处理适配逻辑

*/

public void changeNotchHight(int hight) {

}

华为

注册刘海显示

android:name="android.notch_support"

android:value="true" />

String DISPLAY_NOTCH_STATUS = "display_notch_status";

int mIsNotchSwitchOpen = Settings.Secure.getInt(getContentResolver(),DISPLAY_NOTCH_STATUS, 0);

Toast.makeText(content, "华为手机状态值=" + (mIsNotchSwitchOpen==0?"显示区域":"覆盖耳朵区域"), Toast.LENGTH_LONG).show();

小米

注册刘海屏

android:name="notch.config"

android:value="portrait|landscape" />

获取是否以开启刘海设置

Settings.Global.getInt(content.getContentResolver(), "force_black", 0) == 1//覆盖区域耳朵"

获取状态兰高度 高度比刘海大一点

public int getstatus(Context content){

int result=0;

int resourceId = content.getResources().getIdentifier("status_bar_height", "dimen", "android");

if (resourceId > 0) {

result = content.getResources().getDimensionPixelSize(resourceId);

}

return result;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值