I wanted to use PNG for my buttons but considering that I suck when it comes to graphics, and I do not have the time to surf and learn how to make one with normal and pressed button states, I was lucky to chance upon the Android Button Maker website.
Now, if you only are into those simple and minimalistic styled buttons, this website will help you easily create buttons without using images. Yes, only XML code is needed.
What’s more, when you want to set something like choosing a color, the results are shown in real time. Even the source code too!
The developer did a very good job with this. There are detailed instructions on how to use the XML files in the layout which can also help developers new to Android.
So I would like to say kudos to his work. The developer who made this definitely helped save me quite a lot of time. If there is some easier and quicker way to make a simple button, why make an image, right? It will only add up to memory consumption too ;).
I have to admit, you need to dig in a little Math here. Drawing an equilateral triangle in a Canvas is possible using a Path object or use vertices to set up the 3 points.
However, to do automatic calculation, the best possible way to do this would be to either input 2 points and have the method calculate the 3rd point. In my case, I was able to create a method using only 1 point and specifying the distance.
Remember, an equilateral triangle has the same length on all 3 sides so my method’s other parameter entails having to declare the size per side.
And I was able to make a method where the middle point will be calculated depending on the desired location of the developer.
This is the result of the triangle that the method generates. It returns a Path object where, depending on the direction that you choose will point to that direction.
You may notice there is a 3rd parameter of type Direction. It is just an enum class that I created. You can change it if you want. But if you want to use the same class, here is the code for the Direction enum class.
If you want to create a triangle that faces downward like in the 3rd image above with the number 9, you can do it like this.