android popupwindow 自定义背景,android – 无法将PopupWindow背景设置为透明

我有以下代码:

View child = getLayoutInflater().inflate(R.layout.contextual_menu_lp_activity,null)

child.setBackgroundColor(getResources().getColor(R.color.transparent));

child.setBackgroundDrawable(new BitmapDrawable());

popup = new PopupWindow(MapViewActivity.this);

popup.setContentView(child);

popup.showAtLocation(MapViewActivity.mapView,Gravity.CENTER,10,10);

popup.setBackgroundDrawable(new BitmapDrawable());

child.measure(View.MeasureSpec.UNSPECIFIED,View.MeasureSpec.UNSPECIFIED);

popup.update(50,50,child.getMeasuredWidth(),child.getMeasuredHeight());

正如您所看到的,我设置了视图,并拼命尝试使其背景透明.

在xml布局上,所有相对布局都被赋予透明的颜色背景.

这是xml:

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="@color/transparent" >

android:id="@+id/ivDialogPopup"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:paddingBottom="40dp"

android:background="@drawable/new_pop_up_bk" >

android:id="@+id/btLivePolice"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toLeftOf="@+id/btSaveParkingLocation"

android:layout_marginRight="4dp"

android:layout_marginTop="8dp"

android:background="@drawable/live_police_button_popup" />

android:id="@+id/btSaveParkingLocation"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_marginTop="8dp"

android:layout_centerHorizontal="true"

android:background="@drawable/parking_location_button" />

android:id="@+id/btGetDirections"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="4dp"

android:layout_marginTop="8dp"

android:layout_toRightOf="@+id/btSaveParkingLocation"

android:background="@drawable/directions_button" />

尽管如此,视图的父布局(相对布局)仍然具有灰色背景.

(以前,我使用的是普通的活动类,在清单中我有一个透明的主题 – 最重要的部分是将这个android:windowBackground设置为透明 – 我必须更改它的原因不同).

任何帮助表示赞赏.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值