Search code examples
javaandroidbuttonandroid-custom-view

Custom Button painting on Android


Goal

My goal is to edit a Button so that it's shape is a little triangle with the shape of < and >.

Shape 1         Shape 2

    /|          |\
   / |          | \
  /  |          |  \
 /   |          |   \
/    |          |    \
\    |          |    /
 \   |          |   /
  \  |          |  /
   \ |          | /
    \|          |/

What I know

I never edited the painting process of a Button, so I am kind of lost. I have used Canvas and done some games by overwriting painting functions in Java, however, it's not clear for me how to proceed to achieve this in Android. I know I wil have to do the following things:

  1. Create a class that extends Button
  2. Edit the painting/drawing of it so that it has the shape I want
  3. Create an instace of it and add it to my layout on runtime

Question

  1. What functions do I have to overwrite to do this?
  2. Will the highligting when clicked work well or do I have to fix that too?
  3. Can the click highlight be turned off?

Solution

  • I will just use something like the answer in this other question. Since my shape is a triangle, it will work.