Android implements the dialog function when loading the network
Effect preview
Brief description
Now Android program network request operation is essential, but programs with good interactive experience are particularly important to deal with network time-consuming operations.
Code Description:
dialog_ loading.xml
This layout is our customized display layout. It is relatively simple and clear. The outermost layer is a vertically arranged linear layout, followed by an ImageView and textview.
loading_ animation.xml
This is the basic attribute operation of the rotation attribute animation we set. This XML exists in the anim folder under res (create the folder manually)
This class is a custom ProgressDialog. I have written comments on the key steps of the code.
use
In the above code, we see that I add a button in the main activity to realize its click event. In the click event, I create an asynchronous operation to simulate the network time-consuming. Notice that I introduced a style when creating CustomProgressDialog, and the system was suck by default, so I could only write one by myself.
The parameter meaning of attribute is interested in Baidu, which will not be introduced one by one here.
The implementation code is so simple but very practical. I hope it will be helpful to all readers. Finally, attach the complete code:
http://xiazai.jb51.net/201702/yuanma/CustomProgressDialog
The above is what Xiaobian introduced to you. Android realizes the dialog function when loading the network. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!