zoukankan      html  css  js  c++  java
  • PopupWindow

    效果图:popupWindow.gif

    弹窗布局:

    <?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="match_parent"
                  android:background="#000"
                  android:orientation="vertical">
    
        <Button
            android:id="@+id/btn_popup_windows_item1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="Item1"
            android:textSize="18sp"/>
    
        <Button
            android:id="@+id/btn_popup_windows_item2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="Item2"
            android:textSize="18sp"/>
    
    </LinearLayout>
    
    
    void showPopupWindow(View view){
    
            View viewpw =View.inflate(TestActivity.this,R.layout.item_popup_window_layout,null);
            Button btn1=(Button) viewpw.findViewById(R.id.btn_popup_windows_item1);
    
            //设置背景透明效果 (注意Background必须背景色)(范围0~255)
            viewpw.getBackground().setAlpha(100);
    
            //创建PopupWindow 并设置宽 高
            final PopupWindow popupWindow = new PopupWindow(viewpw,
                    ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
    
            //设置焦点,这样的或就可以实现点击popupWindow外部区域,关闭popupWindow
            popupWindow.setFocusable(true);
    
            //设置显示位置
            popupWindow.showAsDropDown(view, 60,0); //指定View的下方
            //popupWindow.showAtLocation(view, Gravity.CENTER,0,0);  //屏幕中心
    
            btn1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(TestActivity.this, "You click Item1", Toast.LENGTH_SHORT).show();
                    popupWindow.dismiss(); //关闭 PopupWindow
                }
            });
        }
    
    文章部分内容摘自网络和图书,如有侵权,请联系我。
  • 相关阅读:
    memory runs at single channel问题解决
    ASP php获取文件URL地址等方法
    zencart的modules下数据库操作templates排版和common首页引用
    php生成html 伪静态??
    Linux服务器自动备份压缩MySQL数据库的实用方法
    dos 命令集
    Zencart 500错误查找和解决方法
    破解JS加密:url unicode加密而已
    .htaccess 保护文件夹
    TCP 的那些事儿(上)
  • 原文地址:https://www.cnblogs.com/-Tiger/p/7347857.html
Copyright © 2011-2022 走看看