版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LM_ZP/article/details/52145050
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;
}
});