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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:36:47+00:00 2026-05-19T17:36:47+00:00

I have created a custom Button as follows. file : buttoncontrol.xml <?xml version=1.0 encoding=utf-8?>

  • 0

I have created a custom Button as follows.

file : buttoncontrol.xml

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/greendot"
          android:state_pressed="true" />
    <item android:drawable="@drawable/reddot" />
</selector>

in the layout file.. I have used

    <Button
     ...
        android:background="@drawable/buttoncontrol"></Button>

When I try to run the program the layout shows the button with reddot (expected result). When I press the button, it turns green until I release the keypress. How can I make this green until the next click. More a toggle behaviour.

I have tried the same xml file in a toggle button as well. Same result.

Apart from this (for testing), I have also tried adding the following code in activity as well. Still not getting the desired result. (which is saving the state)

...under onClick of  Button/ToggleButton
buttonControl.setPressed(true);

Any suggestions? My preference is to avoid programatically controlling the state. i.e. I can always keep these images and use buttonContol.setBackgroundDrawable for the buttons

Thanks

  • 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-19T17:36:48+00:00Added an answer on May 19, 2026 at 5:36 pm

    I made ToggleButton work by changing android:state_pressed=”true” to android:state_checked=”true” .

    But the question still remains for Button. How to make button do a similar activity? Particularly when there are more than 2 states.

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

Sidebar

Related Questions

I have created a custom dialog and a layout xml: <?xml version=1.0 encoding=utf-8?> <LinearLayout
I have created a custom Button class and I want to be able to
This way i have created my custom button and set the image.I have set
I have created a custom web control to act as a button with an
I have created a custom control in C# ( Overridden methods in Button control
I have created a custom button using this code setup : function(ed) { ed.addButton('Tittle',
I'm trying to create a custom control - a button - which will have
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I
I have created a custom dialog for Visual Studio Setup Project using the steps
If have created a custom role within SqlServer which I added to the db__denydatareader

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.