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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:18:50+00:00 2026-05-19T09:18:50+00:00

I made a button that changes the background drawable on different states, this way:

  • 0

I made a button that changes the background drawable on different states, this way:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="true" android:drawable="@drawable/btn_location_pressed" /> <!-- pressed -->
     <item android:state_focused="true" android:drawable="@drawable/btn_location_pressed"/> <!-- focused -->
     <item android:drawable="@drawable/btn_location"/> <!-- default -->
</selector>

The problem here is that I’m also trying to change the textColor as I do with the drawable but I’m not being able to. I already tried android:textColor and android:color but the first doesn’t work whilst the seconds changes my background.

The next code is part of my layout. Regarding to the text color it only works for the normal state text color, thus not changing it to the white one while pressed

<Button android:id="@+id/location_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dp"
        android:background="@drawable/location"          
        android:textSize="15sp"
        android:textColor="@color/location_color"
        android:textColorHighlight="#FFFFFF"
   />

Has anybody got a clue?

  • 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-19T09:18:51+00:00Added an answer on May 19, 2026 at 9:18 am

    Create a stateful color for your button, just like you did for background, for example:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <!-- Focused and not pressed -->
        <item android:state_focused="true" 
              android:state_pressed="false" 
              android:color="#ffffff" />
    
        <!-- Focused and pressed -->
        <item android:state_focused="true" 
              android:state_pressed="true" 
              android:color="#000000" />
    
        <!-- Unfocused and pressed -->
        <item android:state_focused="false" 
              android:state_pressed="true" 
              android:color="#000000" />
    
        <!-- Default color -->
        <item android:color="#ffffff" />
    
    </selector>
    

    Place the xml in a file at res/drawable folder i.e. res/drawable/button_text_color.xml. Then just set the drawable as text color:

    android:textColor="@drawable/button_text_color"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I've made a form in Cakephp 2.1 with a jQuery button that appends
I made an extension for IE9 that adds a toolbar button. The registration looks
I've made a popup div that shows a video if you press a button.
I've made a button background from shapes and is looking quite good for my
I have an anchor tag <a class=next>next</a> made into a button. Sometimes, this tag
I'm styling a form that was already marked up (made some markup changes), and
I have created a UIButton programmatically that correctly changes background color as desired when
I have got some markup that looks like this: <div class=button> <span class=image></span> <input
I made a button component in Delphi, and I write a code with error
I made a login button and want to check if the user logged in

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.