Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6557159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:02:18+00:00 2026-05-25T13:02:18+00:00

My application shows some notifications, and depending on user preferences it might use a

  • 0

My application shows some notifications, and depending on user preferences it might use a custom layout in a notification. It works well, but there is a small problem — text colors. Stock Android and almost all manufacturer skins use black text against a light background for notification text, but Samsung doesn’t: their notification pulldown has a dark background and the text in the default notification layout is white.

So this causes a problem: the notifications that don’t use any fancy layouts show up fine, but the one that uses a custom layout is hard to read because the text is black instead of the default white. Even the official documentation just sets a #000 color for a TextView, so I couldn’t find any pointers there.

A user was kind enough to take a screenshot of the problem:

Screenshot

So how do I use the default notification text color from the device in my layouts? I’d rather not start dynamically altering the text color based on phone model, since that requires a lot of updating and people with custom ROM’s might still get the problem, depending on the skin they’re using.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:02:19+00:00Added an answer on May 25, 2026 at 1:02 pm

    Solution by Malcolm works fine with API>=9. Here’s the solution for older API:

    The trick is to create the standard notification object and then traverse the default contentView created by Notification.setLatestEventInfo(...). When you find the right TextView, just get the tv.getTextColors().getDefaultColor().

    Here’s the code that extracts the default text color and text size (in scaled density pixels – sp).

    private Integer notification_text_color = null;
    private float notification_text_size = 11;
    private final String COLOR_SEARCH_RECURSE_TIP = "SOME_SAMPLE_TEXT";
    
    private boolean recurseGroup(ViewGroup gp)
    {
        final int count = gp.getChildCount();
        for (int i = 0; i < count; ++i)
        {
            if (gp.getChildAt(i) instanceof TextView)
            {
                final TextView text = (TextView) gp.getChildAt(i);
                final String szText = text.getText().toString();
                if (COLOR_SEARCH_RECURSE_TIP.equals(szText))
                {
                    notification_text_color = text.getTextColors().getDefaultColor();
                    notification_text_size = text.getTextSize();
                    DisplayMetrics metrics = new DisplayMetrics();
                    WindowManager systemWM = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
                    systemWM.getDefaultDisplay().getMetrics(metrics);
                    notification_text_size /= metrics.scaledDensity;
                    return true;
                }
            }
            else if (gp.getChildAt(i) instanceof ViewGroup)
                return recurseGroup((ViewGroup) gp.getChildAt(i));
        }
        return false;
    }
    
    private void extractColors()
    {
        if (notification_text_color != null)
            return;
    
        try
        {
            Notification ntf = new Notification();
            ntf.setLatestEventInfo(this, COLOR_SEARCH_RECURSE_TIP, "Utest", null);
            LinearLayout group = new LinearLayout(this);
            ViewGroup event = (ViewGroup) ntf.contentView.apply(this, group);
            recurseGroup(event);
            group.removeAllViews();
        }
        catch (Exception e)
        {
            notification_text_color = android.R.color.black;
        }
    }
    

    Call extractColors ie. in onCreate() of your service. Then when you’re creating the custom notification, the color and text size you want are in notification_text_color and notification_text_size:

    Notification notification = new Notification();
    RemoteViews notification_view = new RemoteViews(getPackageName(), R.layout.notification);       
    notification_view.setTextColor(R.id.label, notification_text_color);
    notification_view.setFloat(R.id.label, "setTextSize", notification_text_size);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a web application that shows some controls and descriptions dynamically (I don't
I have an application that shows a list of items. The user can click
I am developing a Qt application that can play the videos and shows some
I am able to deploy my application but for some reason, I am not
I want to make an opengl application that shows some 3d graphics and a
My application needs to download some big Files. I use a service for the
I am writing this very basic J2SE application which alerts the user with some
My application needs to show some notifications for schedules (like Alarm), based on time
I would like to show some hidden text in a Flex application and have
I am using a PreferenceActivity to show some settings for my application. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.