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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:54:52+00:00 2026-06-05T23:54:52+00:00

Here are 2 screenshots, they dont have the same size because the left is

  • 0

buttons

Here are 2 screenshots, they dont have the same size because the left is from emulator the right from the device. Should have taken both from the device, sorry for this.

Both use the same drawable.

Left: background set in the layout:

        <ImageButton
        android:id="@+id/backFromOldCurves"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/backunpressed"
        android:paddingLeft="10sp"
        android:paddingRight="10sp"
        android:src="@drawable/navigationpreviousitem" />

Right: background set dynamically in onTouch on ACTION_UP:

public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        v.setBackgroundDrawable(getResources().getDrawable(R.drawable.backpressed));

    }
    if (event.getAction() == MotionEvent.ACTION_UP) {
        v.setBackgroundDrawable(getResources().getDrawable(R.drawable.backunpressed));
        onClick(v);

    }

    return true;

}

Casting the Drawable to NinePatchDrawable in setBackgroundDrawable doesnt work.
How could i work this around ?

  • 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-05T23:54:54+00:00Added an answer on June 5, 2026 at 11:54 pm

    Why you don’t use

    v.setBackgroundResource(R.drawable.backpressed);
    

    ?

    Edit: Don’t return true in onTouch(). Return false and you won’t have to call onClick() when MotionEvent.ACTOIN_UP gets triggered.

    public boolean onTouch(final View v, final MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            v.setBackgroundResource(R.drawable.backpressed);
        case MotionEvent.ACTION_UP:
            v.setBackgroundResource(R.drawable.backunpressed);
        default:
            Thread.sleep(50); // sleep for performance, otherwise you'd get flooded with ACTION_MOVE
        }
        return false; // return false to not consume the event
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read other questions here, but they seem to be for Xcode 3.2
Here's how it looks like right now: my screenshot Is there a way for
Here is my problem step by step, 1- I do ajax get request from
So here's my problem. I have two tables, photos and users_homepage_photos . In my
Here is the code I have : <ScrollViewer Grid.Row=2 CanContentScroll=True> <DockPanel> <TreeView x:Name=tView DockPanel.Dock=Top
Newbie to .NET data apps here, coming from a Visual Foxpro background. I'm planning
I have 3 .ttf files in my iPhone app. They represent these 3 fonts:
I have built a navigation list for a client and they opted to use
Here is a screenshot of my Project: The lines hidden behind the error window
Here's a screenshot of my AlertDialog's unresponsive state: In the background, the green tile,

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.