Android刘海屏、水滴屏全面屏适配方案,海量算法高频面试题精编解析

  1. 对Activity生效,意味着可以针对单个页面进行刘海屏适配,设置了该属性的Activity系统将不会做特殊处理:




方案二

对Application生效,意味着该应用的所有页面,系统都不会做竖屏场景的特殊下移或者是横屏场景的右移特殊处理

我的NotchScreenTool中使用的就是方案二,如果需要针对Activity,建议自行修改。

  1. 设置应用窗口在华为刘海屏手机使用刘海区

/刘海屏全屏显示FLAG/
public static final int FLAG_NOTCH_SUPPORT=0x00010000;
/**

  • 设置应用窗口在华为刘海屏手机使用刘海区
  • @param window 应用页面window对象
    */
    public static void setFullScreenWindowLayoutInDisplayCutout(Window window) {
    if (window == null) {
    return;
    }
    WindowManager.LayoutParams layoutParams = window.getAttributes();
    try {
    Class layoutParamsExCls = Class.forName(“com.huawei.android.view.LayoutParamsEx”);
    Constructor con=layoutParamsExCls.getConstructor(LayoutParams.class);
    Object layoutParamsExObj=con.newInstance(layoutParams);
    Method method=layoutParamsExCls.getMethod(“addHwFlags”, int.class);
    method.invoke(layoutParamsExObj, FLAG_NOTCH_SUPPORT);
    } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException |InstantiationException
    | InvocationTargetException e) {
    Log.e(“test”, “hw add notch screen flag api error”);
    } catch (Exception e) {
    Log.e(“test”, “other Exception”);
    }
    }
  1. 清除添加的华为刘海屏Flag,恢复应用不使用刘海区显示

/**

  • 设置应用窗口在华为刘海屏手机使用刘海区
  • &#
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值