android實(shí)現(xiàn)常駐通知欄遇到的問題及解決辦法
實(shí)現(xiàn)常駐通知欄時(shí)遇到的問題:
無論如何就是不顯示通知,查看日志發(fā)現(xiàn)貌似報(bào)錯(cuò)了:
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)
說的是布局報(bào)錯(cuò),所使用的布局如下:
根據(jù)報(bào)錯(cuò)信息來看,就是這個(gè)
android.support.constraint.ConstraintLayout
的問題了。
然后將布局的根view修改為RelativeLayout。
運(yùn)行,報(bào)錯(cuò),,,,納尼?
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)
雖然繼續(xù)報(bào)錯(cuò),但是發(fā)現(xiàn)跟第一次報(bào)的錯(cuò)不同了,說明第一個(gè)報(bào)錯(cuò)問題解決。
那么來細(xì)看第二個(gè)報(bào)錯(cuò)信息:
Binary XML file line #2: You must supply a layout_height attribute.
看信息是說布局中缺少layout_height屬性,但是確認(rèn)布局中設(shè)置了這屬性啊。。。
<?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="多云轉(zhuǎn)晴" 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="空氣優(yōu)" 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="浦東新區(qū) 14:33發(fā)布" 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>
莫名奇妙啊簡直
然后仔細(xì)想想可能的原因:難不成是因?yàn)榉直媛蔬m配的問題?
就是沒有匹配到合適的分辨率的尺寸。那就試一下,把布局中所有引用@dimen的地方直接改為使用尺寸。
運(yùn)行,成功?。?!
問題:發(fā)現(xiàn)有個(gè)布局上的問題
自定義通知欄設(shè)置了背景,寬度是match_parent,但是發(fā)現(xiàn)在某些手機(jī)上,如小米6(截圖所示),可以看到寬度竟然沒有充滿全屏。
但是在華為, vivo等手機(jī)上正常。
那就把這個(gè)背景去掉,自適應(yīng)好了。
總結(jié)
到此這篇關(guān)于android實(shí)現(xiàn)常駐通知欄遇到的問題及解決辦法的文章就介紹到這了,更多相關(guān)android 常駐通知欄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Android Fragment實(shí)現(xiàn)底部通知欄
- Android通知欄前臺(tái)服務(wù)的實(shí)現(xiàn)
- Android App自動(dòng)更新之通知欄下載
- 適配Android 8.0版本更新安裝與通知欄的一些坑
- Android 下載文件通知欄顯示進(jìn)度條功能的實(shí)例代碼
- Android 8.0系統(tǒng)中通知欄的適配詳解
- Android 8.0系統(tǒng)中通知欄的適配微技巧
- Android開發(fā)實(shí)現(xiàn)判斷通知欄是否打開及前往設(shè)置頁面的方法
- 關(guān)于Android中點(diǎn)擊通知欄的通知啟動(dòng)Activity問題解決
- Android 通知欄的使用方法
相關(guān)文章
Android客戶端實(shí)現(xiàn)注冊、登錄詳解(2)
這篇文章主要為大家詳細(xì)介紹了Android客戶端實(shí)現(xiàn)注冊、登錄代碼第二篇,App與服務(wù)器的交互實(shí)現(xiàn)登錄和自動(dòng)登錄功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11Android 自定義TextView實(shí)現(xiàn)文本內(nèi)容自動(dòng)調(diào)整字體大小
本文主要介紹了Android 自定義TextView實(shí)現(xiàn)文本內(nèi)容自動(dòng)調(diào)整字體大小以適應(yīng)TextView的大小的方法。具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-03-03Android實(shí)現(xiàn)自動(dòng)點(diǎn)擊無障礙服務(wù)功能的實(shí)例代碼
這篇文章主要介紹了Android實(shí)現(xiàn)自動(dòng)點(diǎn)擊無障礙服務(wù)功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04Android TextWatcher監(jiān)控EditText中的輸入內(nèi)容并限制其個(gè)數(shù)
本篇文章主要介紹了Android TextWatcher監(jiān)控EditText中的輸入內(nèi)容并限制其個(gè)數(shù),我們可以通過TextWatcher去觀察輸入框中輸入的內(nèi)容,有興趣的可以了解一下。2017-04-04Flutter實(shí)現(xiàn)網(wǎng)絡(luò)請求的方法示例
這篇文章主要介紹了Flutter實(shí)現(xiàn)網(wǎng)絡(luò)請求的方法示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-03-03Android編程實(shí)現(xiàn)向桌面添加快捷方式的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)向桌面添加快捷方式的方法,結(jié)合實(shí)例形式詳細(xì)分析了Android添加桌面快捷方式的操作技巧,需要的朋友可以參考下2016-11-11Android實(shí)現(xiàn)截圖分享qq 微信功能
在日常生活中,經(jīng)常用到qq,微信截圖分享功能,今天小編通過本文給大家介紹Android實(shí)現(xiàn)截圖分享qq 微信功能,具體實(shí)現(xiàn)代碼大家參考下本文2017-12-12Android時(shí)分秒計(jì)時(shí)器的兩種實(shí)現(xiàn)方法
這篇文章主要介紹了Android時(shí)分秒計(jì)時(shí)器的兩種實(shí)現(xiàn)方法,分別是Chronometer控件和handler+timer+timerTask方式,非常不錯(cuò),感興趣的朋友一起看下吧2016-08-08Android中的廣播(BroadCast)詳細(xì)介紹
這篇文章主要介紹了Android中的廣播(BroadCast)詳細(xì)介紹,本文講解了什么是廣播、廣播有什么用、實(shí)現(xiàn)廣播、動(dòng)態(tài)注冊方式、配置文件方式等內(nèi)容,需要的朋友可以參考下2015-03-03