【自定义】
pop_version.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:gravity="right" android:orientation="vertical"> <LinearLayout android:layout_width="144dp" android:layout_height="69dp" android:layout_marginTop="45dp" android:layout_marginRight="10dp" android:background="@drawable/cab_button_white" android:orientation="vertical"> <TextView android:layout_width="113dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="17dp" android:text="版本号:" android:textColor="@color/textBlack" android:textSize="@dimen/text_color_12" /> <TextView android:id="@+id/tv_version" android:layout_width="113dp" android:layout_height="wrap_content" android:layout_gravity="center" android:text="v1.0 (11011028)" android:textColor="@color/textBlack" android:textSize="@dimen/text_color_12" /> </LinearLayout> </LinearLayout>
drawable下 cab_button_white.xml
<!-- Style for "1" --><!-- Add this snippet to layer-list xml in drawable. --> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/textWhite" /> <corners android:radius="8dp" /> </shape>
【背景变暗并Pop取消时背景色还原】
WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.alpha = 0.7f; getWindow().setAttributes(lp); mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.alpha = 1f; getWindow().setAttributes(lp); } });
【 ActivityPopWindow所有显示】:
private void PopLogVersion() { View mView = LayoutInflater.from(this).inflate(R.layout.pop_version, null, false); PopupWindow mPopupWindow = new PopupWindow(mView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); //PopWindow弹出时,图标不消失 mPopupWindow.setFocusable(true); mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); mPopupWindow.setOutsideTouchable(true); mPopupWindow.showAtLocation(mView, Gravity.TOP | Gravity.RIGHT, 0, 0); //设置PopWindow背景颜色。 WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.alpha = 0.7f; getWindow().setAttributes(lp); //给Pop设置监听,取消Popt弹出时的背景颜色。 mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.alpha = 1f; getWindow().setAttributes(lp); } }); }