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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:01:12+00:00 2026-06-01T17:01:12+00:00

I have an android application that has a button which I want to have

  • 0

I have an android application that has a button which I want to have black text and background while it is disabled and then a green background with white writing when it is enabled.

Ive got the enabling and disabling working but if I change the colors the button stays the same regardless of its state.

I’ve read that I need to use a custom selector to set the colors manually and this is what I have got so far:

continuebutton.xml in res/drawable:(green is declared in /res/values/colors.xml)

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item 
android:state_enabled="false"
    android.textColor ="@android:color/black"
    android:drawable="@android:color/black" />
<item 
    android:state_enabled="true"
    android.textColor ="@android:color/white"
    android:drawable="@color/green" />

continuebutton in layout xml file:

 android:id="@+id/continueButton"
   android:layout_width="200dp"
    android:layout_height="55dp"  android:layout_gravity="center" android:paddingTop="10dp" android:textSize="18dp" 
    android:text="@string/continueButton" android:background="@drawable/continuebutton" />

I think I’m doing something wrong in the continuebutton.xml file but I’m not sure how to fix it.

Any help would be greatly appreciated!

Thanks

UPDATE:

I have the background changing color, the last problem is resolve is the text color which is staying black regardless of whether the button is disabled or enabled(should be white for enabled).

Do i need to make a new xml file in res/drawable for the text color?

Any ideas?

  • 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-06-01T17:01:13+00:00Added an answer on June 1, 2026 at 5:01 pm

    Remove the attribute

    android:src="@drawable/continuebutton"
    

    and use

    android:background="@drawable/continuebutton"
    

    at runtime you can change the background image by

    myButton.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.myfirstbg));
    myButton.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.mysecondbg));
    

    if you want to use background Color remove both properties`

    android:src="@drawable/continuebutton"
    android:background="@drawable/continuebutton"
    

    and change background color by using this

    myButton.setBackgroundColor(Color.BLUE);
    myButton.setBackgroundColor(Color.GREEN);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an android application that has 3 activites. For the 1st and 2nd
I have an android application that displays a toast every hour and then every
I have a problem with my android application. That application which uses the kSOAP
I have a big text file (5Mb) that I use in my Android application.
I know that Android doesn't have an Application-level onPause the way an Activity has
I currently have a notification in my Android application that has a PendingIntent so
I'm having a strange problem with Android 1.6 I have an application that has
I have an Android application that contains two Activities . Activity A has a
I have an android application in which I take a photo.For that I'm building
I have an Android application which has a login screen. Upon the click 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.