转载自:http://blog.csdn.net/caroline_wendy/article/details/50115525
Android的Rom版本非常多, 通知栏颜色也各有不同, 如HTC是白底, 红米Note是暗色透明, 也有其他黑底, 灰底等. 统一设置相同的字体颜色, 必然会导致颜色冲突. 那么如何设置字体颜色, 可以正常显示呢?
如HTC(5.0), 标题和内容的颜色已经和系统完全相同, 字体大小是适配的.
如红米Note, 标题和内容的颜色统一使用StatusBar字体的颜色.
通知的逻辑
RemoteViews views = new RemoteViews(mAppContext.getPackageName(), R.layout.view_notification); views.setImageViewResource(R.id.notification_iv_portrait, getSmallIcon()); views.setTextViewText(R.id.notification_tv_calories, getContentText()); 123 123通知的背景默认系统背景, 字体颜色@style/TextAppearance.StatusBar.EventContent.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tool="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="64dp" android:gravity="center_vertical"> ... <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toEndOf="@+id/notification_iv_portrait" android:layout_toRightOf="@+id/notification_iv_portrait" android:gravity="center_vertical" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/notification_widget_title" android:textAppearance="@style/TextAppearance.StatusBar.EventContent" android:textSize="@dimen/d14sp"/> <TextView android:id="@+id/notification_tv_calories" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="@style/TextAppearance.StatusBar.EventContent" android:textSize="@dimen/d20sp" tool:text="10步 | 20大卡"/> </LinearLayout> </RelativeLayout> 1234567891011121314151617181920212223242526272829303132 1234567891011121314151617181920212223242526272829303132TextAppearance.StatusBar.EventContent, 顾名思义StatusBar的事件内容文本样式. 在系统中, 会默认匹配, 如灰色等.
新建layout-v21, 表面5.0版本以后使用.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tool="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="64dp" android:gravity="center_vertical"> <ImageView android:id="@+id/notification_iv_portrait" android:layout_width="70dp" android:layout_height="64dp" android:paddingBottom="8dp" android:paddingTop="8dp" android:scaleType="centerInside" tool:src="@drawable/widget_normal"/> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toRightOf="@+id/notification_iv_portrait" android:gravity="center_vertical" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/notification_widget_title" android:textAppearance="@android:style/TextAppearance.Material.Notification.Title" android:textSize="14sp"/> <TextView android:id="@+id/notification_tv_calories" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="@android:style/TextAppearance.Material.Notification.Line2" android:textSize="20sp" tool:text="10步 | 20大卡"/> </LinearLayout> </RelativeLayout> 1234567891011121314151617181920212223242526272829303132333435363738394041 1234567891011121314151617181920212223242526272829303132333435363738394041@android:style/TextAppearance.Material.Notification.Title通知栏标题. @android:style/TextAppearance.Material.Notification.Line2通知栏内容. 这样就可以完全匹配系统颜色.
OK, 这个问题已经解决了.