java--android--PopupWindow

简单弹窗PopupWindow

      //弹框t
    PopupWindow popupWindow = new PopupWindow();
    //宽高必须要有
    popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

    //点击外部取消
    popupWindow.setOutsideTouchable(true);

       

    //加载布局
    View inflate = LayoutInflater.from(this).inflate(R.layout.popu, null);
    popupWindow.setContentView(inflate);//设置布局
    View activity_main = LayoutInflater.from(this).inflate(R.layout.activity_main, null);
    //在activity_main布局的最下
  	popupWindow.showAtLocation(activity_main, Gravity.BOTTOM,0,0);

    //显示到某个控件的下边
    //popupWindow.showAsDropDown(add);


    //控件里的点击事件
    inflate.findViewById(R.id.sao).setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {
         Toast.makeText(MainActivity.this, "hhhhhhh", Toast.LENGTH_SHORT).show();
     }
 });

控件里的点击事件:点击扫一扫,吐司:hhhhhhh

接下来就是布局文件

 <TextView
            android:id="@+id/sao"
            android:textColor="#fff"
            android:textSize="20sp"
            android:gravity="center"
            android:text="扫一扫"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值