Popuwindow 简单实用

首先添加的依赖为 compile 'com.example.zhouwei.library:library:1.0.0'

除此之外还有popupwindow 布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="@drawable/menu_pop_bg"
              android:padding="10dp"
    >
  <LinearLayout
      android:id="@+id/menu1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:gravity="center"
      >
      <ImageView
          android:layout_width="25dp"
          android:layout_height="25dp"
          android:src="@mipmap/mersj2x"
          />
      <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textColor="@android:color/black"
          android:text="我的商家"
          android:layout_marginLeft="10dp"
          />
  </LinearLayout>
    <LinearLayout
        android:id="@+id/menu2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_marginTop="10dp"
        >
        <ImageView
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:src="@mipmap/mersq2x"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/black"
            android:text="申请"
            android:layout_marginLeft="10dp"
            />
    </LinearLayout>


</LinearLayout>

然后只需要在点击实现中添加一个自定义的方法 

//点击事件中自定义的方法 我这里是showPopMenu(); 设置成全全局就行

private void showPopMenu() {
        View contentView = LayoutInflater.from(this).inflate(R.layout.pop_menu,null);
        //处理popWindow 显示内容,这里面也嵌套了一个方法是显示内容的
        handleLogic(contentView);
        //创建并显示popWindow
        mCustomPopWindow= new CustomPopWindow.PopupWindowBuilder(this)
                .setView(contentView)
                .create()
                //backImgjiaTitletree 这个是我做点击事件的空间,点击后出现PopWindow布局效果
                .showAsDropDown(backImgjiaTitletree,0,20);
    }
//这个方法嵌套在showPopMenu()中,
handleLogic();
 private void handleLogic(View contentView) {
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mCustomPopWindow!=null){
                    mCustomPopWindow.dissmiss();
                }
                String showContent = "";
                switch (v.getId()){
                    case R.id.menu1:
                        showContent = "点击 Item菜单1";
                        break;
                    case R.id.menu2:
                        showContent = "点击 Item菜单2";
                        break;


                }
                Toast.makeText(MerchantActivity.this,showContent,Toast.LENGTH_SHORT).show();
            }
        };
        contentView.findViewById(R.id.menu1).setOnClickListener(listener);
        contentView.findViewById(R.id.menu2).setOnClickListener(listener);

    }

按照我的方法做就ok了,这个是参考 https://github.com/pinguo-zhouwei/CustomPopwindow 的链接可以看看各种效果已经显示出来了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值