Creating customs controls in Android

不打扰是莪最后的温柔 提交于 2019-12-11 23:29:10

问题


I want to create my own custom controls in Android application and use them in this way: In the XML file:

<MyButton .... />

I would like to define MyButton some where in the resources XML


回答1:


Create your own subclass of View (e.g., com.ofirbit.MyButton) and then reference it in your layouts (e.g., <com.ofirbit.MyButton android:id="..." />). Here is an Android library project and demonstration sub-project showing an implementation of a custom ColorMixer widget and its use in an application. The details of how to implement one of these can be found in some Android books, the Android documentation, and perhaps elsewhere.



来源:https://stackoverflow.com/questions/4545906/creating-customs-controls-in-android

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