PopupWindow设置背景

一些常用的方法设置PopupWindow的属性

这里写图片描述

  • 效果图如上,怎么给PopupWindow加背景?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"  android:layout_width="match_parent"
    android:background="#66000000"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_alignParentBottom="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <GridView
        android:id="@+id/gridview"
        android:numColumns="6"
        android:background="#ffffff"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    </LinearLayout>
</RelativeLayout>

代码设置

mPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); //设置宽度 布局文件里设置的没有用
        mPopupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);  //设置高度  必须代码设置

在最外层布局 设置上你要的背景android:background=”#66000000”属性,

  • 怎么设置动画
 //设置动画
        mPopupWindow.setAnimationStyle(R.style.AnimTheme);

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AnimTheme">
        <item name="android:windowEnterAnimation">@anim/show</item>
        <item name="android:windowExitAnimation">@anim/hide</item>
    </style>

</resources>

show.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0"
        android:toYDelta="0"
        android:toXDelta="0"
        android:fromYDelta="100%"
        android:duration="2000"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        />
</set>

hide.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AnimTheme">
        <item name="android:windowEnterAnimation">@anim/show</item>
        <item name="android:windowExitAnimation">@anim/hide</item>
    </style>

</resources>

其他的一些属性设置方法

  //4者的属性必须设置
        mPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); //设置宽度 布局文件里设置的没有用
        mPopupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);  //设置高度  必须代码设置
        mPopupWindow.setContentView(window_view);  //设置布局
        //popupWindow.showAsDropDown(window_view);  //设置显示位置

        mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
        mPopupWindow.setOutsideTouchable(true); //外部是否可点击 点击外部消失
        mPopupWindow.setFocusable(true);  //响应返回键  点击返回键 消失

        View parentView = LayoutInflater.from(this).inflate(R.layout.activity_main, null);
        mPopupWindow.showAtLocation(parentView, Gravity.BOTTOM, 0, 0);      //相对父布局
        // mPopupWindow.showAsDropDown(mBt, 0, 0);   //相对某个控件显示

暂时整理这么多,后期会更新加入新的知识点。

源码下载地址

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值