The combination control of Android custom view is similar to the top bar of e-commerce app
This example shares the combined control of Android custom view, imitating the relevant code of the top column of e-commerce app for your reference. The specific contents are as follows
design sketch:
Analysis: there can be textview and button on the left and right sides. Set drawabletop. The middle looks like EditText. However, if you have used apps like Taobao tmall, you will find that click search is not conducted in the current actit, but jump to another page. Use textview and set the background. Realize the process
Parameter list:
Set attribute file: create attrs.xml file under values and add attributes to be customized
Get the properties set in the layout file from the code:
Set background color:
setBackgroundColor(back_color);
Add button:
Add the middle textview: (the layout is arranged in the order of addition, so the middle textview should be added between the two buttons):
Handle wrap of height_ Content attribute:
Override the onmeasure property to wrap_ Content sets a specified value
Add click event:
You need to customize a callback
Create a callback and create the setx method
Add click event when adding button
At this point, the custom composite control is completed. The following is the method to use:
Layout file:
Code settings:
Final effect:
The above is the whole content of this article. I hope it will help you learn Android Software programming, and I hope you can support programming tips.