android实现常驻通知栏遇到的问题及解决办法
作者:唐人小调 发布时间:2022-10-12 06:06:58
实现常驻通知栏时遇到的问题:
无论如何就是不显示通知,查看日志发现貌似报错了:
2020-06-28 14:11:34.923 6387-6387/xxx E/CrashReport: android.app.RemoteServiceException: Bad notification posted from package xxx: Couldn't inflate contentViewsandroid.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1944)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:192)
at android.app.ActivityThread.main(ActivityThread.java:6815)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:818)
说的是布局报错,所使用的布局如下:
根据报错信息来看,就是这个
android.support.constraint.ConstraintLayout
的问题了。
然后将布局的根view修改为RelativeLayout。
运行,报错,,,,纳尼?
2020-06-28 14:24:02.622 11436-11436/xxx E/CrashReport: android.app.RemoteServiceException: Bad notification posted from package xxx: Couldn't inflate contentViewsandroid.view.InflateException: Binary XML file line #2: Binary XML file line #2: You must supply a layout_height attribute.
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1944)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:192)
at android.app.ActivityThread.main(ActivityThread.java:6815)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:818)
虽然继续报错,但是发现跟第一次报的错不同了,说明第一个报错问题解决。
那么来细看第二个报错信息:
Binary XML file line #2: You must supply a layout_height attribute.
看信息是说布局中缺少layout_height属性,但是确认布局中设置了这属性啊。。。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_74"
android:background="@drawable/shape_bg_resident_notify">
<ImageView
android:id="@+id/iv_resident_weather"
android:layout_width="@dimen/dp_45"
android:layout_height="@dimen/dp_45"
android:layout_marginStart="@dimen/dp_10"
android:background="@mipmap/weather_icon_blue_big_cloudy"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/tv_resident_weather_temp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="28"
android:textSize="@dimen/sp_40"
android:textColor="#ff333333"
android:layout_toEndOf="@+id/iv_resident_weather"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/dp_5"/>
<TextView
android:id="@+id/tv_resident_degree"
android:layout_width="@dimen/dp_6"
android:layout_height="@dimen/dp_6"
android:layout_marginStart="@dimen/dp_3"
android:layout_marginTop="@dimen/dp_24"
android:layout_toEndOf="@+id/tv_resident_weather_temp"
android:background="@drawable/shape_resident_weather_temp"/>
<TextView
android:id="@+id/tv_resident_weather_cond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="多云转晴"
android:textSize="@dimen/sp_16"
android:textColor="@color/color_333333"
android:layout_marginTop="@dimen/dp_14"
android:layout_marginStart="@dimen/dp_6"
android:layout_toEndOf="@+id/tv_resident_degree" />
<TextView
android:id="@+id/tv_resident_temp_range"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="21~34℃"
android:textColor="@color/color_333333"
android:textSize="@dimen/sp_16"
android:layout_marginTop="@dimen/dp_5"
android:layout_below="@+id/tv_resident_weather_cond"
android:layout_toEndOf="@+id/tv_resident_degree"
android:layout_marginStart="@dimen/dp_6"/>
<TextView
android:id="@+id/tv_resident_aqi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="空气优"
android:textSize="@dimen/sp_16"
android:textColor="@color/color_333333"
android:layout_alignParentEnd="true"
android:layout_marginTop="14dp"
android:layout_marginEnd="@dimen/dp_10"/>
<ImageView
android:id="@+id/iv_resident_aqi"
android:layout_width="@dimen/dp_18"
android:layout_height="@dimen/dp_18"
android:src="@drawable/ic_icon_aqi"
android:layout_toStartOf="@+id/tv_resident_aqi"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginTop="@dimen/dp_16"/>
<TextView
android:id="@+id/tv_resident_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="浦东新区 14:33发布"
android:textSize="@dimen/sp_12"
android:textColor="@color/color_999999"
android:layout_marginEnd="@dimen/dp_10"
android:layout_alignParentEnd="true"
android:layout_below="@+id/tv_resident_aqi"
android:layout_marginTop="@dimen/dp_11"/>
</RelativeLayout>
莫名奇妙啊简直
然后仔细想想可能的原因:难不成是因为分辨率适配的问题?
就是没有匹配到合适的分辨率的尺寸。那就试一下,把布局中所有引用@dimen的地方直接改为使用尺寸。
运行,成功!!!
问题:发现有个布局上的问题
自定义通知栏设置了背景,宽度是match_parent,但是发现在某些手机上,如小米6(截图所示),可以看到宽度竟然没有充满全屏。
但是在华为, vivo等手机上正常。
那就把这个背景去掉,自适应好了。
来源:https://blog.csdn.net/gengbaolong/article/details/106997947


猜你喜欢
- 类1.什么是类类是事物的属性(外在特征)和行为(具备的功能)的集合2.想要知道Java中类是什么我们要先知道现实生活中的类是什么,因为Jav
- 快速排序算法概念快速排序一般基于递归实现。其思路是这样的:1.选定一个合适的值(理想情况中值最好,但实现中一般使用数组第一个值),称为“枢轴
- 一:串口通信简介前段时间因为工作需要研究了一下android的串口通信,网上有很多讲串口通信的文章,我在做的时候也参考了很多文章,现在就将我
- 本文实例讲述了Java获取UTC时间的方法。分享给大家供大家参考,具体如下:取得本地时间:java.util.Calendar cal =
- 前言在做项目的时候,遇到一个需求,需要我对Chart图标标记数据正在运行,实现数据可视化,因为我们的表格是隐藏Y轴的刻度是看不到数据值的,于
- spring batch简介spring batch是spring提供的一个数据处理框架。企业域中的许多应用程序需要批量处理才能在关键任务环
- 这篇文章使用Java组件显示窗口,在通过输入的图片url地址在窗口中显示出来,可作为一个网络图片查看器,感兴趣的可以打包成jar或者.exe
- 1、基本介绍随着分词在信息检索领域应用的越来越广泛,分词这门技术对大家并不陌生。对于英文分词处理相对简单,经过拆分单词、排斥停止词、提取词干
- —学习并使用mybatis-plus的一些高级功能的用法例如: AR模式、 乐观锁 、逻辑删除 、自动填充、数据保护等功能为了方便演示,咱们
- 访问者(Visitor)模式:封装一些作用于某种数据结构中的各元素的操作,它可以在不改变这个数据结构的前提下定义作用于这些元素的新的操作。访
- Android studio开发工具中,如何如何删除Android项目,下面是在Android studio 1.5正式版删除Android
- 本文通过老王和小王买车,引出设计模式中的结构型设计之桥接模式,接着说明设计型模式的概念和代码实现,为了加深理解,会说明适配器设计模式在JDB
- 条形码,是由宽度不等的多个黑条和空白所组成,用以表达一组信息的图形标识符。通过给文档添加条形码,可以直观,快捷地访问和分享一些重要的信息。本
- Rss 是一种描述和同步网站内容的格式,是目前使用最广泛的XML应用。RSS 搭建了信息迅速传播的一个技术平台,使得每个
- 解决C#中WebBrowser的DocumentCompleted事件不执行的实现方法 :使用WebBrowser的ProgressChan
- 在网上很多关于dubbo异常统一处理的博文,90%都是抄来抄去。大多都是先上一段dubbo中对于异常的统一处理的原码,然后说一堆的(甚至有1
- 1、写在前面今天群里一个小伙伴问了这样一个问题,扩展方法与实例方法的执行顺序是什么样子的,谁先谁后(这个问题会在文章结尾回答)。所以写了这边
- 总之是用jdbc 的游标移动package com.sp.person.sql.util; import java.sql.Connecti
- 一副扑克有54张牌:大小王+4*13,接下来我们来模拟一下斗地主的发牌过程首先,我们需要买牌,新买来的牌都是按顺序摆放的,因此下一步是洗牌,
- Java自定义异常类的实例详解为什么要自己编写异常类?假如jdk里面没有提供的异常,我们就要自己写。我们常用的类ArithmeticExce