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

  • Home
  • SEARCH
  • 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 3673716
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:46:01+00:00 2026-05-19T02:46:01+00:00

I have a preference group called Credentials and I’d like to change the color

  • 0

I have a preference group called “Credentials” and I’d like to change the color of that header based on whether the credentials are valid or not.

I keep a reference to the credentials item by grabbing it when I start up my PreferenceActivity

// ... code ...
public enum CredentialsInfo {
    VALID, INVALID, UNKNOWN
}

private Preference credentials;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.my_preferences);

    credentials = findPreference(getString(R.string.credentials));
    // ... etc ...
}

Once I am done verifying my credentials I run a function called updateCredentialsBarColor that is supposed to load the correct drawable and set the credentials Preference to the appropriate color. Though when I try to change the color nothing happens. Am I getting the view incorrectly and if so, what is the proper way to get it?

private void updateCreditialsBarColor(CredentialsInfo state) {
    Drawable background = null;
    switch(state) {
    case VALID:
        background = getResources().getDrawable(R.drawable.credentials_state_valid);
        break;
    case INVALID:
        background = getResources().getDrawable(R.drawable.credentials_state_invalid);
        break;
    case UNKNOWN:
    default:
        background = getResources().getDrawable(R.drawable.credentials_state_unknown);
        break;
    }
    if(background != null) {
        View credentialsView = credentials.getView(null, null);
        credentialsView.setBackgroundDrawable(background);
    }
}
  • 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-19T02:46:02+00:00Added an answer on May 19, 2026 at 2:46 am

    Um, that looks good. Are you sure updateCreditialsBarColor() gets called? After all, there’s a typo in the method name, AFAICT.

    You might also dump some logging information in that method and compare it to the results of examining your activity in Hierarchy Viewer to see if you’re getting the View you think you are.

    You might also consider creating a custom subclass of whatever Preference this is that encapsulates this behavior.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a checkbox preference that takes the user to a
I have an SQL table called trainings that looks like this: +-----+-----------+--------+------------+------------+------------+-------+ | Id
Which is your preference? Let's say we have a generic Product table that has
I'm looking for a best practice solution.... I have table that holds products called
I have a field called time_elapsed that stores a sql TIME value, a start_date
I'd like to create a simple reference app that lists a group of people,
I have joined a new group that has coding guidelines that (to me) seem
Does any one have a preference on how to check if a value is
Does anyone here use VB.NET and have a strong preference for or against using
I would like some of my preferences to have icons, like the Settings app.

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.