我正在嘗試在通知欄上顯示圖示和文本。所以我為此創建了一個新布局,但是只顯示文本而圖示不顯示。
這就是我創建通知的方式:
val notification = NotificationCompat.Builder(this, notificationChannelId)
.setOngoing(true)
.setContentTitle(getString(R.string.app_name))
.setCustomBigContentView(RemoteViews(packageName, R.layout.notification_view))
.setSmallIcon(R.drawable.ic_launcher)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pendingIntent)
.build()
這是我的通知布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent">
<ImageView
android:id="@ id/ic_someid"
android:layout_width="15dp"
android:layout_height="15dp"
app:srcCompat="@drawable/ic_someicon" />
<TextView
android:id="@ id/text_sometext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test..." />
</LinearLayout>
我的問題是為什么圖示沒有出現在通知欄中?
uj5u.com熱心網友回復:
替換app:srcCompat="@drawable/ic_someicon"為android:src="@drawable/ic_someicon"。您不能在任何場景(自定義通知、應用小部件等)中使用app-prefixed 屬性。RemoteViews
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/514406.html
標籤:安卓科特林
