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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:50:03+00:00 2026-06-09T01:50:03+00:00

in my xml file i have this button : <Button android:id=@+id/button_8 android:layout_width=0dp android:layout_height=wrap_content android:text=@string/Bf

  • 0

in my xml file i have this button :

<Button
android:id="@+id/button_8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/Bf"
android:background="@drawable/button_purple" 
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="action"            
/>

And in my activity i have this method for the button :

public void action (View v)
{
    s = "m";
    changeCouleur("blue");
    v.setPressed(true);
}

When i pressed the button it’s working but the button don’t stay pressed.

I don’t use an image this is what i use for the color :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>
            <solid
                android:color="#449def" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item android:state_focused="true" >
        <shape>
            <solid
                android:color="#449def" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item>
        <shape>
            <gradient
                android:startColor="#449def"
                android:endColor="#2f6699"
                android:angle="270" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="4dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>

I tried toggle button but that doesn’t fit with what i trying to do.
Thanks in advance if you noticed something wrong.

  • 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-09T01:50:04+00:00Added an answer on June 9, 2026 at 1:50 am

    maybe you can change the button to an image
    then you can create animation when the button pressed

    this is an example

    Bitmap source0 = BitmapFactory.decodeResource(getResources(), R.drawable.top);
    Bitmap source1 = BitmapFactory.decodeResource(getResources(), R.drawable.top_a);
    Bitmap source2 = BitmapFactory.decodeResource(getResources(), R.drawable.top_b);
    Bitmap source3 = BitmapFactory.decodeResource(getResources(), R.drawable.top_c);
    v.startAnimation(AnimationUtils.loadAnimation(mainContext, R.anim.image_click));
    toptop.setImageBitmap(source0);
    top_a.setImageBitmap(processingBitmap_Brightness(source1));
    top_b.setImageBitmap(source2);
    top_c.setImageBitmap(source3);
    

    place this code on a ontouch event
    then v.startanimation is for animation when the image touched
    then we set the selected imageview to be highlighted with set the brightness brighter than the other image

    this is the anim.image_click code

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
    
    <alpha
    android:fromAlpha = "1.0"
    android:toAlpha = "0.5"
    android:duration = "300">
    </alpha>
    <scale
    android:fromXScale = "1"
    android:toXScale = "0.9" 
    android:fromYScale = "1"
    android:toYScale = "0.9" 
    android:pivotX="50%"
    android:pivotY="50%" 
    android:duration = "50">
    </scale>
    </set>
    

    and this is is the procssingBitmap_Brightness (for processing the image brightness)

    private Bitmap processingBitmap_Brightness(Bitmap src){
                Bitmap dest = Bitmap.createBitmap(
                  src.getWidth(), src.getHeight(), src.getConfig());
    
                for(int x = 0; x < src.getWidth(); x++){
                 for(int y = 0; y < src.getHeight(); y++){
                  int pixelColor = src.getPixel(x, y);
                  int pixelAlpha = Color.alpha(pixelColor);
    
                  int pixelRed = Color.red(pixelColor) + brightnessValue;
                  int pixelGreen = Color.green(pixelColor) + brightnessValue;
                  int pixelBlue = Color.blue(pixelColor) + brightnessValue;
    
                  if(pixelRed > 255){
                   pixelRed = 255;
                  }else if(pixelRed < 0){
                   pixelRed = 0;
                  }
    
                  if(pixelGreen > 255){
                   pixelGreen = 255;
                  }else if(pixelGreen < 0){
                   pixelGreen = 0;
                  }
    
                  if(pixelBlue > 255){
                   pixelBlue = 255;
                  }else if(pixelBlue < 0){
                   pixelBlue = 0;
                  }
    
                  int newPixel = Color.argb(
                    pixelAlpha, pixelRed, pixelGreen, pixelBlue);
    
                  dest.setPixel(x, y, newPixel);
    
                 }
                }
                return dest;
               }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is an easy question, in my xml file i have : <Button android:id=@+id/button_8
I have one ImageButton in my xml layout like that : <ImageButton android:id=@+id/tabsButton android:background=@drawable/button
I have this xml file which has text init. i.e Hi my name is
I have a main activity with this layout file: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have Button and its text, I retrive it from string.xml i.e. I have
I have this xml file <?xml version=1.0 encoding=UTF-8?> <bo:C837ClaimParent xsi:type=bo:C837ClaimParent xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:bo=http://somelongpathHere/process/bo> <claimAux> ...
I have this simple XML file : <?xml version=1.0 encoding=utf-8 ?> <Artists> <artist artistId=1>
I have this code that reads from XML file. It gets five strings (groupId,
I have this script to generate an XML file for an RSS feed. Works
I have this use case of an xml file with input like Input: <abc

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.