popupWindow使用

xml

<?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:orientation="vertical"
    android:background="#b5555555"
    android:gravity="center"
    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#fff"
         android:layout_margin="25dp"
        >
 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="无法获取当前位置信息"
     android:layout_gravity="center"
     android:textSize="20dp"
     android:layout_marginTop="20dp"
     />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="     为了您申请有效学分,请选择你们单位所在的位置信息"
        android:layout_gravity="center"
        android:layout_margin="20dp"
        />
    <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/width_0.5"
        android:background="#cbcbcb"
        />
    <Button
        android:id="@+id/subject_dialog_button"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="确定"
        android:background="@color/white"
        android:textSize="20dp"
        android:textColor="#33cc33"
        />
    </LinearLayout>
</LinearLayout>
acticity

 View view1 = View.inflate(MySubjectActivity.this, R.layout.activity_subject_dialog, null);
                final PopupWindow popupWindow = new PopupWindow(view1, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
                popupWindow.setFocusable(true); // 设置PopupWindow可获得焦点
                popupWindow.setTouchable(true); // 设置PopupWindow可触摸
                popupWindow.setOutsideTouchable(true); // 设置非PopupWindow区域可触摸
                popupWindow.setBackgroundDrawable(new BitmapDrawable(getResources()));;//
                popupWindow.showAtLocation(back注:它为标志性物,Gravity.CENTER, 0, 0);
                Button dialog_button= (Button) view1.findViewById(R.id.subject_dialog_button);
                dialog_button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent1 = new Intent(MySubjectActivity.this, MySubjectMap.class);
                        startActivity(intent1);
                        popupWindow.dismiss();
                    }
                });
                view1.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (popupWindow != null && popupWindow.isShowing()) {
                            popupWindow.dismiss();
                        }
                        return false;
                    }
                });




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值