popwindow底部弹窗

popwindow使用
最终实现的效果:
这里写图片描述

1.popwindow 布局文件:popwindow.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="325dp"
    android:layout_gravity="bottom"
    android:layout_height="150dp">
<LinearLayout
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:background="#16c233"
    android:gravity="center_vertical"
    android:layout_height="30dp">
    <Button
        android:id="@+id/btn_confirm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#16c233"
        android:textSize="15sp"
        android:textColor="#ffffff"
        android:text="@string/book_ensure"/>
    <Button
        android:id="@+id/btn_cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#16c233"
        android:layout_marginLeft="80dp"
        android:textSize="15dp"
        android:textColor="#ffffff"
        android:text="@string/cancel"
        />
</LinearLayout>

    <ListView
        android:id="@+id/lv_workNum"
        android:background="#ffffff"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></ListView>

</LinearLayout>

2.popwindow 设置

  LayoutInflater mLayoutInflater = LayoutInflater.from(this);
        contentView = mLayoutInflater.inflate(R.layout.popupwindow, null);
        pop = new PopupWindow(contentView, 750, 450);//布局、宽高
        Button ensure = (Button) contentView.findViewById(R.id.btn_confirm);
        Button cancel = (Button) contentView.findViewById(R.id.btn_cancel);

        ensure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               if(IsCheckedWorkerNum){
                  ......
                    pop.dismiss();
               }else{
                   ......
               }
            }
        });
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop.dismiss();
            }
        });

        ListView listView = (ListView) contentView.findViewById(R.id.lv_workNum);

        // 产生背景变暗效果

        WindowManager.LayoutParams lp = activity. getWindow().getAttributes();

        lp.alpha = 0.4f;

        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        activity.getWindow().setAttributes(lp);

        pop.setTouchable(true);

        pop.setFocusable(true);

        pop.setBackgroundDrawable(new BitmapDrawable());

        pop.setOutsideTouchable(true);//点击外部,popwindow消失

        pop.showAtLocation(contentView, Gravity.BOTTOM, 0, 0);

        pop.update();

        pop.setOnDismissListener(new PopupWindow.OnDismissListener() {

            // 在dismiss中恢复透明度

            public void onDismiss() {
             popDismiss();
            }

        });

        workerNumAdapter=new  WorkerNumAdapter(this,works);
        listView.setAdapter(workerNumAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                workerNumAdapter.setSeclection(position);
                workerNumAdapter.notifyDataSetChanged();
                workerNum=works[position];
                IsCheckedWorkerNum=true;
            }
        });

3.恢复透明度

 private void popDismiss(){
        WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
        lp.alpha = 1f;        
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        activity.getWindow().setAttributes(lp);

    }

相关推荐:
1.http://www.cnblogs.com/sw926/p/3230659.html
2.http://www.cnblogs.com/mengdd/p/3569127.html
3.https://my.oschina.net/lhjtianji/blog/54530
4.简单demo:http://download.csdn.net/detail/huangbiao86/3966917

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值