0

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?

J0hj0h
  • 894
  • 1
  • 8
  • 34

3 Answers3

1

[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.

Community
  • 1
  • 1
Somil
  • 481
  • 3
  • 8
  • I tried using an `ImageButton` and adding the XML-attribute android:focusable="false". But when I click on the button, it still gets a blue highlight. – J0hj0h Jul 08 '14 at 17:14
  • Awesome, that is exactly what I need, apparently. I will soon look further into this! Thanks! – J0hj0h Jul 08 '14 at 17:43
1

Just use ImageView

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

dreambit.io dreambitio
  • 1,892
  • 1
  • 15
  • 24
  • I used a selector to change the pressed state of the "button". That leaves only point 3, but it is not that important... Thank you for this suggestion! – J0hj0h Jul 08 '14 at 17:28
0

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

android:setBackground = "#0AAA"
user3259330
  • 448
  • 6
  • 9
Ayoze Pérez
  • 28
  • 1
  • 5