PopupWindow-pop-up window, popupwindow-pop-up window

Source: Internet
Author: User

PopupWindow-pop-up window, popupwindow-pop-up window

 
1 
 
2 knowledge points
  PopupWindow (View contentView, int width, int height) // create a popup window without obtaining focus, Length: width, width: height, and content: cntentView.
PopupWindow (View contentView, int width, int height, boolean focusable) // similar to the one above, however, the fourth parameter can be used to control whether to obtain the focus. // (these two parameters are used more )!!!!
3. Dialog Box
 layout_about_popup.xml
<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: background = "@ color/bg_about_popup" android: orientation = "vertical"> <LinearLayout android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_margin = "5dp" android: orientation = "horizontal"> <LinearLayout android: id = "@ + id/ll_0000_1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orientation = "vertical"> <ImageView android: layout_width = "50dp" android: layout_height = "50dp" android: layout_gravity = "center_horizontal" android: background = "@ drawable/button_effec_effecpressed"/> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_gravity = "center_horizontal" android: layout_margin = "5dp" android: text = "friend" android: textSize = "13sp"/> </LinearLayout> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_weight = "1"/> <LinearLayout android: id = "@ + id/ll_0000_2" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orientation = "vertical"> <ImageView android: layout_width = "50dp" android: layout_height = "50dp" android: layout_gravity = "center_horizontal" android: background = "@ drawable/button_mirror_4_pressed"/> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_gravity = "center_horizontal: layout_margin = "5dp" android: text = "" android: textSize = "13sp"/> </LinearLayout> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_weight = "1"/> <LinearLayout android: id = "@ + id/ll_0000_3" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orientation = "vertical"> <ImageView android: layout_width = "50dp" android: layout_height = "50dp" android: layout_gravity = "center_horizontal" android: background = "@ drawable/button_share_2_pressed"/> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_gravity = "center_horizontal" android: layout_margin = "5dp" android: text = "QQ login" android: textSize = "13sp"/> </LinearLayout> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_weight = "1"/> <LinearLayout android: id = "@ + id/ll_0000_4" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orientation = "vertical"> <ImageView android: layout_width = "50dp" android: layout_height = "50dp" android: layout_gravity = "center_horizontal" android: background = "@ drawable/button_share_3_pressed"/> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_gravity = "center_horizontal" android: layout_margin = "5dp" android: text = "Weibo login" android: textSize = "13sp"/> </LinearLayout> <ImageView android: layout_width = "match_parent" android: layout_height = "0.5dp" android: layout_marginBottom = "5dp" android: background = "@ android: color/black"/> <Button android: id = "@ + id/btn_share_call_off" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_gravity = "center_horizontal" android: background = "@ color/transparent" android: text = "cancel"/> </LinearLayout>
4 button_share_1_pressed.xml
<?xml version="1.0" encoding="UTF-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/login_share_2_0" android:state_pressed="false"></item><item android:drawable="@drawable/login_share_2_1" android:state_pressed="true"></item></selector>

5. java

    private LinearLayout layout_weixin;    private LinearLayout layout_weixin_friends;    private LinearLayout layout_qq;    private LinearLayout layout_sina;    private Button btn_out_off;    private View view;    private PopupWindow pop;
// Introduce the window configuration file-the pop-up window interface view = inflater. inflate (R. layout. layout_about_popup, null); layout_weixin = (LinearLayout) view. findViewById (R. id. ll_share_1); layout_weixin_friends = (LinearLayout) view. findViewById (R. id. ll_0000_2); layout_qq = (LinearLayout) view. findViewById (R. id. ll_1__3); layout_sina = (LinearLayout) view. findViewById (R. id. ll_0000_4); btn_out_off = (Button) view. findViewById (R. id. btn_share_call_off );
// PopupWindow instantiate pop = new PopupWindow (view, LayoutParams. MATCH_PARENT, LayoutParams. WRAP_CONTENT, true); pop. setAnimationStyle (R. style. MenuAnimationFade );

 

@Override    public void onClick(View v) {        switch (v.getId()) {        case R.id.ic_about_back:            finish();            break;        case R.id.ic_about_help:            Uri uri = Uri.parse("http://www.etoury.com/help/app.html");            Intent it = new Intent(Intent.ACTION_VIEW, uri);            startActivity(it);            break;        case R.id.btn_about_share:            /* share(); */            changePopupWindowState();            break;        case R.id.ll_share_1:            finish();            break;        case R.id.ll_share_2:            finish();            break;        case R.id.ll_share_3:            finish();            break;        case R.id.ll_share_4:            finish();            break;        case R.id.btn_share_call_off:            changePopupWindowState();            break;        default:            break;        }    }
/*** Change the display and hide of PopupWindow */private void changePopupWindowState () {if (pop. isShowing () {// hide the window. If the window disappears after you click it, you do not need to hide pop. dismiss ();} else {// The content view is displayed in the pop-up window. By default, the content view starts from the lower left corner of the anchored view. Click pop here. showAtLocation (TV _about_version, Gravity. BOTTOM, 0, 0 );}}

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.