0

I am trying to apply a transparent background to my row when it is pressed in my ListView. I create the file list_selector.xml like this:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/argb80804040" />
</selector> 

and in my news_item.xml, I define the back ground as follow:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/list_selector">

<ImageView
   android:id = "@+id/img"
   android:layout_width="95dip"
   android:layout_height="75dip"
   android:layout_alignParentLeft = "true"
   android:paddingTop="10dip"
   android:layout_marginLeft="10dip"
   android:paddingBottom="10dip"
   android:src="@drawable/no_news_image_small" />     

<TextView android:id="@+id/title"
    android:layout_gravity="center_vertical"
    android:layout_width="fill_parent"
    android:layout_weight="1.0"
    android:layout_height="wrap_content" 
    android:textSize="12sp" 
    android:textStyle="bold"
    android:paddingTop="5dip"
    android:layout_marginLeft="110dip"
    android:textColor="#21B6EF"
    android:singleLine="true" />

<TextView android:layout_gravity="center_vertical"
    android:layout_width="fill_parent"
    android:layout_weight="1.0"
    android:layout_height="wrap_content" 
    android:layout_marginLeft="110dip" 
    android:textSize="10sp" 
    android:id="@+id/description" 
    android:layout_below="@id/title"
    android:paddingBottom="10dip" 
    android:layout_marginBottom="5dip" 
    android:textColor="#fff"/>

</RelativeLayout>

However, it displays as solid color instead of ARGB color. My drawable is define as follow:

<resources>
    <item type="drawable" name="transparent_orange">#64ff7b00</item>
    <item type="drawable" name="argb80804040">#80804040</item>
    <item type="drawable" name="argb40000000">#40000000</item>
    <item type="drawable" name="argb80408040">#80408040</item>
</resources>

Do I need to do something else to get aplha color working? I am trying on my own device (motorola defy), and i am also using another application that uses the same alpha color and the color appears ok in this application, but in mine, it doesnt.

Many thanks for any response T

Thiago
  • 5,152
  • 11
  • 35
  • 44

1 Answers1

0

I don't really understand what do you want to achieve but my proposal will be

Define your colors in res/values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="transparent_orange">#64ff7b00</color>
  ...
</resources>

Then you can define a drawable to be used as a background like this in res/drawable/test.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <solid android:color="@color/transparent_orange" />
</shape>

Finally, you can use the resulting drawable as an attribute of the target container with

android:background="@drawable/blue_linear_gradient"
Renaud
  • 8,783
  • 4
  • 32
  • 40
  • @Renaud thank you. I tested you example here, it works but the color is not transparent. IT seems that my the alpha value is not working. I get a solid orange color without any transparency. I have here plenty of sample ARGB color codes, but any of them work as ARGB color since no transparency is applied. – Thiago Jun 30 '11 at 19:46
  • @Thiago: the use of in the shape definition (applied to a TextView with android:background="@drawable/the_shape" and a LinearLayout with android:background="#ffffff") does work here. Could you provide a minimal example on which we could work? – Renaud Jun 30 '11 at 20:22
  • I am using a RelatyveLayout with android:background="@drawable/list_selector", and inside the list_selector I have the . The RelativeLayout is the parent layout element of my list item, so i am applying the transparent background to it. Still not getting transparency, only solid orange color. Thanks @Renaud – Thiago Jun 30 '11 at 20:43
  • http://stackoverflow.com/questions/4247385/how-to-change-color-of-listview-items-on-focus-and-on-click and http://stackoverflow.com/questions/3506319/android-linearlayout-with-color-resource-what-am-i-doing-wrong will be of interest – Renaud Jun 30 '11 at 21:48
  • Well, i will have to give up... i tried both example and nothing... only solid colors and no transparency. I have applications running on my device that successfully apply transparency, but mine app is not doing it. Thanks – Thiago Jun 30 '11 at 22:18
  • @Renaud I used the application andColors to generated ARGB codes for me. In there i selected a blue transparent and got the code #600088FF. However, when I use this code in my application, i am getting a color totally diferent... its almost close to yellow... This is the result: http://pho.to/78QQ1Z – Thiago Jun 30 '11 at 22:29
  • Are you sure you did not define another background color somewhere? It seems to me that transparency work and the "yellow" is the result of the combination. – Renaud Jun 30 '11 at 23:00
  • You wont believe me, but i am not defining another background color, i have no idea about what is going on, i tried many things and can get it to work. Thanks a lot for your help @Renaud – Thiago Jun 30 '11 at 23:15
  • @Thiago let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/1033/discussion-between-renaud-and-thiago) – Renaud Jun 30 '11 at 23:16