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 6546619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:43:47+00:00 2026-05-25T11:43:47+00:00

i am trying to apply the style that a list item has, when it

  • 0

i am trying to apply the style that a list item has, when it is selected, to a View (In my case a TextView)

Example

here it would be the orange-painted style. I found that this look is defined by a Drawable Object. So i tried, so get the drawable and applied it to my view

TextView tv = new TextView(this);     

tv.setText("Hello, Android");
tv.setBackgroundDrawable(new ListView(this).getSelector());
setContentView(tv);

but it doesn’t work.
Does anybody have an idea how to do that?


Ok I figured out how to do that. I found out hat ListView uses the ColorStateList list_selector_background which is defined in android.R.drawable. Using ResourceBrowser I got to know that the fourth color is the selected drawable so i added the following to my code

StateListDrawable listDrawables= (StateListDrawable)getResources().getDrawable(android.R.drawable.list_selector_background);
listDrawables.selectDrawable(3);
Drawable highlightDrawable = listDrawables.getCurrent();

Now I can set my Background using higlightDrawable. I don’t know if it is possible to access the drawable in xml I did not try it yet. Thanks for help!

  • 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-25T11:43:47+00:00Added an answer on May 25, 2026 at 11:43 am

    It would be a pain to do it by code.

    You need to implement a selector and let android know which resource needs to be used when the view is pressed, enabled or focused.

    Here is sample example on how to achieve the same.

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

Sidebar

Related Questions

I have a given markup that I'm trying to apply to some style on.
I'm trying to apply a style that will highlight the whole row if one
Check out my example here: http://timkjaerlange.com/foobar/test.html I'm currently trying to apply a class to
I've got a WPF app that has a listbox which I'm trying to apply
I'm trying to apply a specific style to a slider control and I'm having
I'm trying to grab data from a MySQL database. Approach 2 - apply/map style
so i have been trying to style a scrollviewer, so that i can change
I am trying to apply an inline-block style to an element (a div to
I'm trying to apply CSS styles to page elements that are dynamically inserted in
I'm trying to make a snippet of javascript that can get a list of

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.