简体   繁体   中英

ARGB not working properly in Android app

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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM