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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:55:48+00:00 2026-06-13T03:55:48+00:00

I need to be able to supply a dynamic behavior for the buttons in

  • 0

I need to be able to supply a dynamic behavior for the buttons in my project. So far the closest I’ve gotten is using an XML like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true" android:drawable="@drawable/mainmenu_button_pressed" /> 
<item android:state_enabled="false" android:drawable="@drawable/mainmenu_button_disabled" />  
<item android:drawable="@drawable/mainmenu_button" /> 

</selector>

This does exactly the trick, but as stated on the question’s topic my project needs this to be dynamic, I’ll explain what I mean…

This application has an intro menu and the several options have different images on them. Depending on a user-made choice at runtime (before this menu) I need to be able to supply a different set of images to the buttons. The ideal way to do this would be:

<item android:state_pressed="true" android:drawable="%MAINMENU_BUTTON_PRESSED%" />

So I could just set %MAINMENU_BUTTON_PRESSED and it would use set A (A_mainpressed.png) or B (B_mainpressed.png) without requiring extra coding.

I’m aware the probably proper way to do this would be using the OnClick function and doing everything programmatically. Considering, however, the ammount of manual work that implies on my project I wanted to first make sure there was really no way of creating a dynamic XML and supplying it to the button so it would work just like that (AFAIK all ressources are compiled and therefore cannot be modified at runtime, also, an XML file on the assets folder won’t work because those are not compiled and hence do not generate an ID that I can supply).

Is there any way to achieve this behavior or should I just swallow it and stick with the OnClick method? 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-06-13T03:55:50+00:00Added an answer on June 13, 2026 at 3:55 am

    Nevermind, found the answer on another post…** Keyword was “selector”. I barely have any experience on Android so I didn’t exactly know how to look for this (a friend actually hinted about the selector and so I found that). Thanks for the help anyways guys.

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

Sidebar

Related Questions

I need to be able to access a list throughout my Rails project. For
I need to able to access controller methods from a model using the Kohana
I am using as3 air and testing on an android. I need to able
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to
I need to be able to search through multiple 2D arrays and search the
I need to be able to create an id for a hyperlink. I have
I need to be able to strip out a condition in a string, here
I need to be able do the following on a TR: onmouseover highlight the
I need to be able to map out in coordinates real world cities and

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.