Notification bar set System font Color

Source: Internet
Author: User

Android has a lot of ROM version, the notification bar color is also different, such as HTC is white, red rice note is dark transparent, there are other black, gray and so on. Uniformly setting the same font color will inevitably result in color collisions. So how to set the font color, you can display it properly?

For example HTC(5.0) , the color of the title and content is exactly the same as the system, and the font size is appropriate.

For example, the color 红米Note of the title and content uniformly uses the color of the StatusBar font.

The logic of the notification

        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());
1. Under version 5.0

Notification background default system background, font color @style/TextAppearance.StatusBar.EventContent .

<?xml version= "1.0" encoding= "Utf-8"?><relativelayoutxmlns: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  =;         <textview  android:layout _width  = "wrap_content"  android:layout_height  = "wrap_content"  android:text  = "@string/notification_widget_title"  android:textappearanc E  = "@style/textappearance.statusbar.eventcontent"  android:textsize  =" @dimen/d14sp "/>         <TextViewandroid: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 steps | 20 kcal "/>                                                                            </linearlayout></relativelayout>

TextAppearance.StatusBar.EventContent, as the name implies, StatusBar the event content text style. In the system, it will be matched by default, such as Gray.

2. version 5.0 and above

New layout-v21 , Surface 5.0 versions are used later.

<?xml version= "1.0" encoding= "Utf-8"?><relativelayoutxmlns: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:o Rientation  =;         <textview  android:layout _width  = "wrap_content"  android:layout_height  = "wrap_content"  android:text  = "@string/notification_widget_title"  android:textappearanc E  = "@android: Style/textappearance.material.notification.title"  android:textsize  = "14sp" />         <TextViewandroid: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 steps | 20 kcal "/>                                                                            </linearlayout></relativelayout>

@android:style/TextAppearance.Material.Notification.TitleThe notification bar header.
The contents of the @android:style/TextAppearance.Material.Notification.Line2 notification bar.
This makes it possible to match the system color exactly.

OK, this problem has been solved.

Reference

Notification bar set System font Color

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.