Open source China Oschina Android Client Source Analysis (4) Customize dialog box

Source: Internet
Author: User

Oschina A quick-action dialog box at the bottom of the main interface, as shown in:

Oschina is implemented in a dialog way, and some people may use Popupwindow to achieve it. Through the analysis of its implementation principle, to learn about their own useful things.

1 layout files, Dialog_quick_option.xml, layout code not difficult

2 Customizing the dialog box class Quickoptiondialog:

2.1 The layout file of the custom dialog box is loaded in the constructor, the control is initialized, and the Quick Picture button's rotation animation (quick_option_close.xml) is completed. I think we should put this part of work into OnCreate ().

2.2 Set the width of the dialog box to the width of the screen in OnCreate ().

WindowManager m = GetWindow (). Getwindowmanager ();

Display d = m.getdefaultdisplay ();

Windowmanager.layoutparams p = GetWindow (). GetAttributes ();

P.width = D.getwidth ();

GetWindow (). SetAttributes (P);

Here, if you need to set a few of the screen width, then you can follow this code to deal with, but actually it is the width of the screen, so there is no need to add this piece of code.

3 The code defines an interface, but the method of setting the listener is commented out, you will find no error, indicating that it does not really use the setup listener.

Public interface Onquickoptionformclick {

void Onquickoptionclick (int id);

}

So, the question is, when can we deal with it like this? According to the interface named "Who clicked"? So after we instantiate the dialog box in the main interface, Quickoptiondialog dialog = new Quickoptiondialog (mainactivity.this); With dialog settings, the listener can be set, when the dialog box controls a click event, the callback tells the main interface to complete the corresponding event processing, such as interface jump.

This will completely extract the code from the dialog box to refactor so that our code does not appear redundant. I'm going to do this later.


Open source China Oschina Android Client Source Analysis (4) Customize dialog box

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.