Is there a way to toggle a button's state until a different button is activated?

One issue I am facing is with a button that has a drawable XML file set as the background. The purpose of this is to change the background color and outline of the button when it is pressed. However, the problem is that these changes only last for a second and then revert back to their original state. Is there a way to make the changed colors stay until a different button is pressed?

<item android:state_pressed="true" >
    <shape>
        <solid
            android:color="#99000000" />
        <stroke
            android:width="1dp"
            android:color="#489d73" />
    </shape>
</item>
<item>
    <shape>
        <gradient
            android:startColor="#66000000"
            android:endColor="#66000000"
            android:angle="270" />

    </shape>
</item>

Answer №1

Design custom background images for different button states. Update the view's background dynamically when switching between buttons.

Answer №2

To ensure the button retains its color until you decide to modify it, you must alter its background programmatically.

Answer №3

To modify the button background using code, follow these steps.

button.setBackgroundRes(R.drawable.custombutton)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Node.js encryption

Hi, I have developed an encryption code and I am now trying to decrypt it in Android using JSON. I have successfully decrypted this code in Node.js. However, when attempting to decrypt it in Android, I encountered an error. Can someone please help me ide ...

Transform the default WordPress gallery into a stunning slideshow with FlexSlider 2 integration

Greetings, I am searching for a solution to modify the default WordPress gallery in order to integrate the FlexSlider 2 plugin. I specifically want to incorporate this module or feature from this link, but I have been unable to figure it out myself. Your ...

Issue encountered when attempting to insert data via node into MySQL database

As a new Node developer, I am in the process of building some initial applications. Currently, I am working on inserting records into a MySQL database using Node. Below is an example of my post method: router.post('/add',function(req,res){ c ...

Issue: Upon attempting to connect to a vsftpd server deployed on AWS using the npm module ssh2-sftp-client, all designated authentication methods have failed

Code snippet for connecting to the vsftpd server sftp.connect({ host: "3.6.75.65" port: "22" username: "ashish-ftp" password: "*******" }) .then(() => { console.log("result") }) .catch((err)=>{ ...

Ensuring User Data is Current in the UI with Firebase Auth Callbacks

Below is the standard method for setting the user state to currentuser that is returned from onAuthStateChanged. I am looking for a useEffect hook that will be triggered whenever there is an update to the user's information. Unfortunately, I am unable ...

Personalize your Datatable export options with Jquery

I am working with a datatable that contains columns with data in the format 'XXXX unit'. For my export, I need to remove the 'unit' part of the data. What specific rule should I implement for this task? exportOptions: { columns: ...

I faced a challenge when attempting to retrieve a JSON object with an XMLHttpRequest, causing the result to be an

My attempts to Fetch and Parse a JSON Object using XMLHttpRequest in Javascript are always unsuccessful, resulting in an empty quotation... function fetchAndParseJSON(target = null) { var response_data = []; ...

Updating state in Vue by utilizing an array of item values

Hello everyone In a simple application, I am attempting to visualize the insertion sort algorithm using Vue. I have successfully written a function that sorts a list of items and returns an array showing each step of the sorting process. The final array i ...

When deploying a microservice on an AKS cluster using Spring Boot, an error of UnsupportedClassVersionError is

Encountering an UnsupportedClassVersionError while attempting to deploy a Java Spring Boot microservice on AKS. Using the "kubectl apply -f file.yaml" command for deployment. Even after compiling with the correct compiler version, the issue persists. Unsur ...

"Utilizing AJAX with JSON in PHP, the callback function is integrated with

Recently, I encountered an issue while developing a web app using Jquery Mobile. I had to make an Ajax/Json request to a PHP file in order to retrieve data from MySQL database. However, when I received the JSON callback and tried to create a "list" from th ...

Error in jQuery when element is not found

On my website, I use multiple jQuery functions, but not all of them are necessary on every page. These functions are all located in one XXX.js file, such as: jQuery(function() { $(".title").slug({ slug:'slug', hide: false }); }); ...

What is the best way to ensure that JavaScript form errors disappear as soon as new input is entered?

Below is the code snippet: var nameInput = formHandle.f_Name; var idInput = formHandle.f_Id; // VALIDATING NAME if(nameInput.value === ""){ nameMsg = document.getElementById("nameErr"); nameMsg.style.background ...

Creating a jQuery plugin that allows for multiple plugin calls with customizable settings

Here is a jQuery plugin that I created: (function($){ $.fn.myPlugin = function(options) { if (!this.length) { return this; } var settings = $.extend(true, {}, $.fn.myPlugin.defaults, options); $w=$(this); $w.bind("click ...

Tips for organizing a JSON request

When making a call to an endpoint using Axios, the response structure may look something like this: items: [ { url: "https://api.example1...", expirationDate: "2019-11-15T00:00:00+01:00" }, { url: "https://api.example2...", expirationDate: "2019-12-20T00: ...

selecting a radio button and saving its value into a JavaScript variable

How can I assign the return value from a JavaScript script function to a variable inside the HTML body? The function will return the selected variable, but how can I assign it to a variable within my HTML body? <body> <form action="somepage.php ...

Chart Vue, Component

I am currently working with a chart implemented using vue-chart. I am facing a challenge where I need to populate the mydata array with data retrieved from the store.js file. I want to automatically push this data into the mydata array without the need for ...

Is there a way to obtain the guild ID during the createGuild event?

Can someone please help me figure out how to get the guild id in the event guildCreate.js? I have tried using guild.id but it returns undefined. Even when I use console.log(guild), it shows a blank space. Using client.guild.id throws an error for id. cons ...

The replacement of classes in ReactJS using JavaScript seems to be malfunctioning

I have been attempting to change the class of a dynamic element when clicked, but none of my solutions seem to be working. Here is what I have tried: handleClick=(event,headerText)=>{ document.getElementsByClassName('sk-reset-filters') ...

Synchronization-free API and callback functions

I am in need of utilizing an asynchronous service. My current approach involves sending data to this service using PHP and CURL, as well as receiving data from a URL provided by the service. How can I effectively respond or wait for feedback from this serv ...

Guide on displaying the contents of a log file in a new window upon clicking a link within a Spring MVC application

One of my main objectives is to have a new browser window open and display the content of an entire log file when a link is clicked. This window should not show an address bar or navigation buttons (Back, Forward). I am currently working on this task in a ...