问题
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