简单明了方便使用的自定义popWindow

private void showSubjectPopupWindow(View view) {//想要选择框在哪个view下面,就把那个view作为参数传递进来

    // 一个自定义的布局,作为显示的内容
    View contentView = LayoutInflater.from(mActivity).inflate(R.layout.pop_home_title,null);
    TextView tvOverdue = (TextView) contentView.findViewById(R.id.tvOverdue);
    TextView tvYesDeal = (TextView) contentView.findViewById(R.id.tvYesDeal);
    TextView tvNoDeal = (TextView) contentView.findViewById(R.id.tvNoDeal);
    TextView popDis = (TextView) contentView.findViewById(R.id.popDis);
    tvOverdue.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ToastUtil.showToast(mActivity,"已经过期");
        }
    });
    tvNoDeal.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ToastUtil.showToast(mActivity,"未处理");
        }
    });
    tvYesDeal.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ToastUtil.showToast(mActivity,"已处理");
        }
    });
    popDis.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popupWindow.dismiss();
        }
    });
    popupWindow = new PopupWindow(contentView,
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);

    //实例化一个ColorDrawable颜色为半透明,已达到变暗的效果
    ColorDrawable dw = new ColorDrawable(0xb0000000);
    // 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框
    // 我觉得这里是API的一个bug
    popupWindow.setBackgroundDrawable(dw);

    // 设置好参数之后再show
    popupWindow.showAsDropDown(view, 0, 0);

}
 
布局文件:
<?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:background="#3f000000"
    android:layout_height="match_parent"
  >
    <LinearLayout
        android:layout_width="match_parent"
        android:background="#fff"
        android:layout_height="80px">
        <TextView
            android:id="@+id/tvNoDeal"
            android:gravity="center"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="未处理"/>
        <View
            android:layout_width="2px"
            android:layout_height="match_parent"
            android:background="#eee"/>
        <TextView
            android:id="@+id/tvYesDeal"
            android:gravity="center"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="已处理"/>
        <View
            android:layout_width="2px"
            android:layout_height="match_parent"
            android:background="#eee"/>
        <TextView
            android:id="@+id/tvOverdue"
            android:gravity="center"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="过期"/>
    </LinearLayout>
   <TextView
       android:id="@+id/popDis"
       android:background="#3f000000"
       android:layout_width="match_parent"
       android:layout_height="match_parent"/>
</LinearLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值