Android uses popwindow as the drop-down box instance code
Recently, I was making a drop-down box. I originally wanted to use spinner, but spinner couldn't meet the project requirements. I asked my classmates and colleagues about it. They were all using popwindow. I looked online. Popwindow is very simple and customizable, which meets my requirements. Therefore, I drew lessons from the code I read online and rolled it up myself. Write a blog in case you forget.
First, write a custom layout. The code is as follows
Step 2: define the popwindow style in the code and bind the click event. The code is as follows:
Note that true in the code is setfocusable. If you want to click the blank space to hide popwindow, setfocusable (true) and setbackground () are essential (pro test).
Finally, add a click event for the space to control the display and hiding of the drop-down box. The code is as follows:
(no good animation effect has been found, so no animation has been added. If you find any good animation, please let us know. Thank you here.)
design sketch:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.