Android Dialog Analysis

Source: Internet
Author: User

Android Dialog Analysis

Android Dialog Analysis

Guided by Dialog, there are three pop-up messages in Android (as far as I know): Dialog, tocast, and notification. The focus today is to analyze the Dialog. Android Dialog is the focus of android interface programming. Of course, android is called a "page program", which reflects the importance of page programming and UI threads.

The directory structure in this article:

1. Several types of Dialog in Android

2. Create Dialog

3. AlertDialog In the Android warning dialog box

4. Android progress box ProgressDialog

5. Date selection box & Time Selection box

6. Dialog Box style window

7. popupwindow

The create dialog box is usually a small window that appears on the current Activity. In this case, the Activity loses focus and the dialog box accepts user interaction (touch RESPONSE event)

First, let's take a look at the Dialog class diagram, so that we can see the property inheritance relationship of the control more clearly.


I. Types of Dialog in Android: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Region + region + 45r/region + M6GiICC9 + LbIv/region + region/yt + region/2jwvcD4KPHA + region + PGJyPgo8L3A + CjxoMj62/region/ release/Y1sa21Luwv/K1xM/Uyr66zdL + stg8L3A + release/release + 1 eLBvdXftcTH + release/yu + release/release + bWxtPK/release + HP1Mq + release + 8 /LvhtffV + release/release + 8O/tM7P1Mq + ttS7sL/release/K/TwvcD4KPHA + release/release + 21 Luwv/release/M8L3A + release + 8rH0rvR + bXEoaM8L3A + authorization + authorization/authorization + authorization/Kxu73is/authorization/K21M/authorization + authorization/Q6NKqx + Wz/bbUu7C/authorization + authorization/authorization + CjxwPsbkyrW + r7jmttS7sL/ release + release/release + release/e + zbK70NCjrL/release/Cw + release/release + y8S49sf40/release + oaTJ + release + oaTNvLHqx/release + examples/examples + examples/examples + oaSwtMWlx/examples + examples/8 s/examples + CjxwPtLUyc + examples/examples + xNrI3b/JtO + 1vbK7zay1xMS/Examples + encrypt/decrypt + CjxwPtLUyc + encrypt/8rv5sb6 + zcrHv8nS1ML61 + PQ6NKqwcujrM /release + LbIv/release + release Zyi9 + LbIttS7sL/release + 7raGqoaq9 + release/y0rK/release/70ru49s/release + LbIv/release/UtcTWsb3Tw + a21L34tsi/ examples/bKx8Pis/examples + xuS + examples + LbIttS7sL/examples + examples/Uyr621Luwv/K8tL/samples + PGJyPgo8L3A + examples/yPC9oMj4KPHA + examples/ release/release + cve-vcd4kpha + release/release + release/rzgzP3G96OstNO2 + release/release + vODM/release + release/Wt723qNbQu/release + wfmhorbUu7C/ release/2qOssqKyu8Tcy + release/Nf2s8nBy7bUu7C/8rfnJiMyNjY4NDu2 + NLRoaM8L3A + release/release + release = "brush: java; ">


VII. popupwindow

Popupwindow can also create a window similar to the dialog box style,Easy to use, two steps:

1. The popupwindow constructor creates a popupwindow object.

2,Two display methods are available:

1. As a drop-down of a control: showAsDropDown (View v)

2. display at the specified position: showAtLocation () is displayed at the specified position.

(The focus in this example is whether the popupwindow disappears when you click an external event. Setting the background is very important)

Packagecom. example. hellopopupwindow; importandroid. OS. bundle; importandroid. app. activity; importandroid. content. context; importandroid. util. log; importandroid. view. layoutInflater; importandroid. view. motionEvent; importandroid. view. view; import android. view. view. onClickListener; importandroid. view. view. onTouchListener; importandroid. view. viewGroup. layoutParams; importandroid. widget. button; importandroid. widget. popupWindow; importandroid. widget. toast; public classMainActivity extends Activity {private Context mContext = null; @ Override protected void onCreate (BundlesavedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); mContext = this; Button button = (Button) findViewById (R. id. button); button. setOnClickListener (newView. onClickListener () {@ Override public void onClick (View view) {showPopupWindow (view) ;}) ;}private void showPopupWindow (View view) {// a custom layout, view contentView = LayoutInflater. from (mContext ). inflate (R. layout. pop_window, null); // set the Button click event button = (Button) contentView. findViewById (R. id. button1); button. setOnClickListener (newOnClickListener () {@ Override public void onClick (View v) {Toast. makeText (mContext, "button is pressed", Toast. LENGTH_SHORT ). show () ;}}); final PopupWindow popupWindow = newPopupWindow (contentView, LayoutParams. WRAP_CONTENT, LayoutParams. WRAP_CONTENT, true); popupWindow. setTouchable (true); popupWindow. setTouchInterceptor (newOnTouchListener () {@ Override public boolean onTouch (View v, MotionEvent event) {Log. I ("mengdd", "onTouch:"); return false; // if true is returned, the touch event will be blocked // The onTouchEvent of PopupWindow will not be called after it is blocked, in this way, you cannot click dismiss} in the external region.) // if the background of PopupWindow is not set, no matter whether you click the external region or the Back key, you cannot dismiss the dialog box. // I think this is a bug in the API popupWindow. setBackgroundDrawable (getResources (). getDrawable (R. drawable. selectmenu_bg_downward); // set the parameter and then show popupWindow. showAsDropDown (view );}}


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.