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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:34:08+00:00 2026-06-13T20:34:08+00:00

In this specific Activity , the user should select the destructor chosen of player

  • 0

In this specific Activity, the user should select the destructor chosen of player 1 and player 2 in a rock paper scissors game.

I tried several approaches: the first one was to simply let the selected ImageButton clicked, but I do not found any solutions to achieve that.

The second was to set the choosen ImageButton unclickable and change its Image, like shown in the Image below. There, the “rock” was choosen for player 1 and nothing for player 2 yet. As you see, as soon I change the Images of an ImageButton, the borders disappear.

enter image description here

I change the status of the Buttons like this

public void onClickRock1(View v){
    choosenDestructor1 = 1;

    buttonRock1.setImageResource(R.drawable.rock_clicked);
    buttonRock1.setBackgroundColor(getResources().getColor(R.color.button_background_stay_clicked));
    buttonRock1.setClickable(false);

    buttonPaper1.setImageResource(R.drawable.paper);
    buttonPaper1.setBackgroundColor(getResources().getColor(R.color.button_background));
    buttonPaper1.setClickable(true);

    buttonScissors1.setImageResource(R.drawable.scissors);
    buttonScissors1.setBackgroundColor(getResources().getColor(R.color.button_background));
    buttonScissors1.setClickable(true);
    }

and for all other 5 Buttons the same in analogy to this method. Now, I consider that overriding the style of the ImageButton with a simple Image make the borders of my custom ImageButton style disappear, but this is only guessing.

I wrote a second custom ImageButton style with different background color and same border, but I can’t figure out how to set that style on the ImageButton from code.

So my question is, which method would be the smartest to solve this (I think is the third one, but maybe there’s another one) and if it is the third one, how to set the style of an ImageButton from code.

EDIT:

In analogy to rgrocha’s answer, I edited my selector (which was already integrated in the custom_imagebutton.xml) like following

<?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/rock">
        <shape>
            <solid
                android:color="@color/button_background" />
            <stroke
                android:width="2dp"
                android:color="#FFF716" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />

        </shape>
    </item>
    <item android:state_selected="true" android:drawable="@drawable/rock_clicked">
        <shape>
            <solid
                android:color="@color/button_background_stay_clicked" />
            <stroke
                android:width="2dp"
                android:color="#FFF716" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item android:drawable="@drawable/rock">        
        <shape>
            <solid
                android:color="@color/button_background" />
            <stroke
                android:width="1dp"
                android:color="#FFFFFF" />
            <corners
                android:radius="0dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>  
</selector>

and the onClickRock1 method like this

public void onClickRock1(View v){
    choosenDestructor1 = 1;
    buttonRock1.setSelected(true);
    buttonPaper1.setSelected(false);
    buttonScissors1.setSelected(false);
}

Solving it like this had the consequence to make a custom_imagebutton.xml for each ImageButton (rock, paper, scissors), and following problems are here:
1. The border is not visible (which matters, because I would like to have these borders)
2. The Image isn’t scaled anymore (which doesn’t matter, because I like it more like this)

So basically, it looks like the image I posted above, except the Images are a little bit bigger due to not scaling (in the layout.xml, I set scaleType="fitCenter")

  • 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-13T20:34:10+00:00Added an answer on June 13, 2026 at 8:34 pm

    You can make a drawable selector for each state you want to apply and set it as the main mage or the background, you choose the better fits your needs.

    In this selector you can make the borders, colors, images, whatever you want change.

    A selector looks like:

    <item android:state_pressed="true">
        <shape android:shape="rectangle" >
    
            <solid android:color="@color/button_highlight" />
            <corners android:radius="5dp" />
    
        </shape>
        </item>
    <item android:state_selected="true">
        <shape android:shape="rectangle" >
    
            <solid android:color="@color/menu_bg_selected" />
            <corners android:radius="5dp" />
    
        </shape>
    </item>
    

    See http://developer.android.com/guide/topics/resources/drawable-resource.html for the full drawables doc. For your case see “State Selector”.

    You can even change the state of the button programatically with setSelected(), setEnabled((), etc.

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

Sidebar

Related Questions

Within a Project form, a user can clone any specific task -- this is
I have an Activity in which user can update a specific information clicking in
This specific questions stems from the attempt to handle large data sets produced by
i have this specific question to do to you, i have a database from
I want to extend RuntimeException to create this specific exception: class CompileLinkException extends RuntimeException
Here is ALL my code for this specific view controller. As the title of
When I run the code for this specific value of dt, an exception is
Alright, this specific layout is just annoying me. And can't seem to find a
I'm trying to remove a specific node from a XmlNodeList named listaWidths. This specific
I'm currently integrating a CMS (developed in PHP) authentication with Active Directory. This specific

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.