Can't remove the black background of a relative layout contains a listView

℡╲_俬逩灬. 提交于 2019-12-13 04:30:04

问题


I'm implementing a custom Dialog which inflates a RelativeLayout xml file

The xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="match_parent"
android:gravity="center_horizontal" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY"
    android:src="@drawable/common_image_list_panel_transparent" />

<ListView
    android:id="@+id/teamListView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="15dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="65dp"
    android:cacheColorHint="#00000000"
    android:divider="@drawable/common_team_list_view_divider"
    android:dividerHeight="1dp"
    android:fadingEdge="none"
    android:scaleType="centerCrop" >
</ListView>

<ImageButton
    android:id="@+id/cancelTeamDialogButton"
    android:layout_width="25dp"
    android:layout_height="25dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="14dp"
    android:layout_marginTop="15dp"
    android:background="@drawable/create_incident_screen_map_overlay_image_close"
    android:gravity="center"
    android:scaleType="fitXY" />

<TextView
    android:id="@+id/listTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="15dp"
    android:gravity="center_horizontal|fill_horizontal|center_vertical|fill_vertical"
    android:textSize="22sp" />

</RelativeLayout>

I tried to change the background color of the RelativeLayout and the ListView but nothing happens. I always get this

I've already removed the background border of the dialog

dialog.getWindow().setBackgroundDrawable(
    new ColorDrawable(getResources().getColor(R.color.transparent)));

The background image is a png with a frame and the rest is transparent and I positioned the ListView inside the frame. what i want is removing the black color from the background which present in side the frame and outside around the rounded corners of the frame.


回答1:


android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"

These two lines will do the trick.




回答2:


Add this attributes to the ListView:

<android:listSelector = "@android:color/transparent"/>
<android:drawSelectorOnTop = "true"/>

Edit: With the previous attributes added to the ListView, then you can put a white background to the Relative Layout, by adding this to it:

<android:background = "@android:color/white"/>



回答3:


I was using AlertDialog instead of Dialog



来源:https://stackoverflow.com/questions/16761653/cant-remove-the-black-background-of-a-relative-layout-contains-a-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!