j-maas
j-maas

Reputation: 906

Making an ImageButton - without button border nor highlight

I have two png-images for the pressed and released state of a button. I'd like to build a button that accomplishes the following:

  1. Has no background/border (only those two images visible)
  2. Does not highlight with a blue rectangle when clicked (only by cycling through those images)
  3. Does not get activated, when the user clicks on a transparent part of the image.

Red button with explamation mark, has the form of a stop sign

As you can see, the button is not rectangular, so the last point mentioned above might be tricky.

I already tried to use an ImageButton and managed to meet point 1, but I failed at point 2.
Is there another View I can use, that does the work for me? If not, could you hint me what techniques I should look into to solve this?

Upvotes: 0

Views: 99

Answers (3)

Ayoze Pérez
Ayoze Pérez

Reputation: 28

If you use setBackground = "#0xxx"; on button in xml file the borders will desappear. Basically making it transparent using alpha

android:setBackground = "#0AAA"

Upvotes: 0

Somil
Somil

Reputation: 481

[Edit] for third part- follow this https://stackoverflow.com/a/8086317/3811198 in short

Use a TouchListener instead of ClickListener

Inside the listener, if the event is MotionEvent.ACTION_DOWN, get the touch coordinates

Check the image's pixel at the coordinates you obtained earlier; if the pixel is not transparent, consider the button was clicked, otherwise ignore the event.

Upvotes: 1

dreambit.io dreambitio
dreambit.io dreambitio

Reputation: 1902

Just use ImageView

One image set as background, second as src. And it resolve all your problems

Upvotes: 1

Related Questions