Is there a way to create a triangular button on Android?

点点圈 提交于 2019-12-08 01:54:22

问题


Is there a way I can create a button which is shaped as a triangle? I know I can put a triangle image as background, but this will make the area outside the triangle clickable. Is there a way to sey the button corners X and Y so I could make it triangular?


回答1:


You can override the OnTouch Event method in a CustomView / CustomButton

Inside you have the MotionEvent were you can check if the Touch was inside your Triangle (with the help of some mathematics :P)




回答2:


If you want to get exotic with non-rectangular views, then you will want to create a custom View. There is lots of information available on the web, but some of the best can be found on the Android documentation site:
http://developer.android.com/guide/topics/ui/custom-components.html#custom



来源:https://stackoverflow.com/questions/9489977/is-there-a-way-to-create-a-triangular-button-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!