android圆角 背景半透明popupWindow

效果图如下


xml文件如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/lay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#b0000000" ><!-- 背景 半透明 -->

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:background="@drawable/popup_window"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:text="battery vehicle error"
            android:textColor="#4b4b4b"
            android:textSize="22sp" />

        <TextView
            android:id="@+id/tv_timeOccur"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="2dp"
            android:gravity="center_vertical"
            android:text="battery vehicle error"
            android:textColor="#676767"
            android:textSize="17sp" />

        <TextView
            android:id="@+id/tv_timeRecover"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="2dp"
            android:gravity="center_vertical"
            android:text="battery vehicle error"
            android:textColor="#676767"
            android:textSize="17sp" />

        <TextView
            android:id="@+id/tv_fault"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="2dp"
            android:gravity="center_vertical"
            android:text="battery vehicle error"
            android:textColor="#676767"
            android:textSize="17sp" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginTop="7dp"
            android:background="#999999" />

        <TextView
            android:id="@+id/btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="10dp"
            android:text="@string/check"
            android:textColor="@color/common_green"
            android:textSize="22sp" />
    </LinearLayout>

</RelativeLayout>

形成圆角的xml文件popup_window.xml内容如下

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 圆角半径 -->
    <corners android:radius="20dp" />
    <!-- 背景颜色 -->
    <solid android:color="#eeeeee" />

</shape>

用到的类,VehiclePopup继承PopupWindow

package com.loopfire.module.dialog;

import com.cwits.cex.picc.R;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;

public class VehiclePopup extends PopupWindow {

	public VehiclePopup(Context context) {
		super(context);
		// setContentView(R.layout.popup_vehicle);
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.popup_vehicle, null);
		this.setContentView(view);
		// 设置SelectPicPopupWindow弹出窗体的宽
		this.setWidth(LayoutParams.MATCH_PARENT);
		// 设置SelectPicPopupWindow弹出窗体的高
		this.setHeight(LayoutParams.MATCH_PARENT);
		// 设置SelectPicPopupWindow弹出窗体可点击
		this.setFocusable(true);
		// 设置SelectPicPopupWindow弹出窗体动画效果
		// this.setAnimationStyle(R.style.AnimBottom);
		// 实例化一个ColorDrawable颜色为全透明
		ColorDrawable dw = new ColorDrawable(-00000);
		// 设置SelectPicPopupWindow弹出窗体的背景
		this.setBackgroundDrawable(dw);
		view.findViewById(R.id.btn).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				VehiclePopup.this.dismiss();
			}
		});
	}

}

然后在要弹出的地方这样就ok了

	VehiclePopup win = new VehiclePopup(getApplicationContext());
				win.showAtLocation(root, Gravity.CENTER, 0, 0);




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值