error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.StatusBar.EventContent.Title'.
在 styles.xml 繼承系統樣式時,**必須加上 @android:style/ 前綴**,否則 aapt 會在專案資源中尋找而非系統資源。
<!-- res/values-v9/styles.xml -->
<resources>
<style name="NotificationText" parent="@android:style/TextAppearance.StatusBar.EventContent" />
<style name="NotificationTitle" parent="@android:style/TextAppearance.StatusBar.EventContent.Title" />
</resources>
res/values/styles.xml <!-- 基礎定義 -->
res/values-v9/styles.xml <!-- API 9+ 覆寫繼承系統樣式 -->
res/values-v21/styles.xml <!-- API 21+ Material Design 微調 -->
<resources>
<style name="NotificationTitle">
<item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
<item name="android:textStyle">bold</item>
</style>
<style name="NotificationText">
<item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
</style>
</resources>
parent="@android:style/Widget.Material.Light.ActionBar"。values-v9 表示 API Level 9 以上套用,低版本回退至 values。?android:attr/textColorPrimaryInverse 隨主題自動適配深/淺色模式。使用 NotificationCompat 搭配 RemoteViews 可跨版本自訂通知佈局,無需處理系統樣式繼承問題:
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setTextViewText(R.id.title, "標題");
contentView.setTextViewText(R.id.text, "內容");
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notify)
.setCustomContentView(contentView)
.build();
修正 @android:style/ 前綴即可解決編譯錯誤;長期建議遷移至 NotificationCompat + RemoteViews 統一管理。