ARGB not working properly in Android app - android

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"

Related

Why button change color when i set a backgroundcolor to the relativelayout in fragment?

this is my fragment
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="135dp"
android:background="#color/colorTerracota"
android:padding="15dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/statetexas"
android:id="#+id/btnTexas"
android:width="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/stateyucatan"
android:id="#+id/btnYucatan"
android:width="100dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/btnTexas"
android:layout_alignStart="#+id/btnTexas" />
</RelativeLayout>
I wanted this see as it:
Set your buttons' background color in your XML file:
android:background:"#9E9E9E" // Your color
Their background is set by default to be transparent.
Create a background selector as below in drawable folder
drawable - selectablebackground.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/grey_lightest" android:state_pressed="true"/>
<item android:drawable="#color/grey_lightest" android:state_focused="true"/>
<item android:drawable="#android:color/white"/>
</selector>
Replace colors as you like for pressed and normal states. Set this as background to your button
android:background:"#drawable/selectablebackground"
This should work.

Android Button with No Padding

I am trying to use the open source antennapod application as a reference for building my android application. I am using ActionBarSherlock and want to create a button at the bottom of my layout that extends from side to side with no padding. It should look like this:
My Styles.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Application.Light" parent="#style/Theme.Sherlock.Light">
<item name="attr/non_transparent_background">#color/white</item>
<item name="attr/borderless_button">#drawable/borderless_button</item>
</style>
</resources>
borderless_button.xml looks like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="#color/selection_background_color_light" />
</shape></item>
<item android:state_focused="true"><shape android:shape="rectangle">
<solid android:color="#color/selection_background_color_light" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="#android:color/transparent" />
</shape></item>
</selector>
attrs.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="borderless_button" format="reference" />
<!-- Used in itemdescription -->
<attr name="non_transparent_background" format="reference" />
</resources>
My Manifest has this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Application.Light" >...</>
My layout is:
<?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:orientation="vertical" >
<LinearLayout
android:id="#+id/footer"
style="#android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="#+id/butConfirm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Search" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/queryString"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="8dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="What would you like to search for?" />
<EditText
android:id="#+id/etxtQueryString"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/queryString"
android:layout_margin="8dp"
android:hint="Enter Query"
android:inputType="textUri" />
</RelativeLayout>
</RelativeLayout>
What it ends up looking like:
I just need one button but still want it to cover the whole width of the screen.
Here is the link to the source code I am using as a guide.
https://github.com/danieloeh/AntennaPod
Any help would be awesome!
Thanks
<Button
android:id="#+id/butConfirm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Search"
android:background="#null"/>
This should do the trick!

Change spinner background

I have created a spinner which looks like
My layout file is:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_corners"
android:padding="7dip" >
<Spinner
android:id="#+id/select_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:prompt="#string/selectCity" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="14dp"
android:text="#string/City"
android:textColor="#color/dark_grey"
android:textSize="18dp" />
</RelativeLayout>
What I want is to make the background of the spinner transparent but still show the downward arrow. Is there any way that I can do this?
Create xml file and place it in drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/slim_spinner_pressed" />
<item android:drawable="#drawable/slim_spinner_normal" />
</selector>
.
<Spinner ..... android:background="#drawable/selector_slim_spinner" ..... />
For more Information Check this Change Spinner Style In Android
You should create a slector and give that selector as background to your spinner
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/..." />
<item android:drawable="#drawable/..." />
</selector>
you can use this resource Android Holo Colors Generator to generate android components like Android 4.0

Android PNG transparent image on background

I have a problem with changing button background image.
So i have 2 images (png-24 transparent background).
Images are a simple circle and the same circle but with some outerglow ).
I have the following code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ticketing_row_topup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#layout/pressed_topup_button"
android:orientation="horizontal" >
<TextView
android:id="#+id/topup_name"
android:layout_width="60dp"
android:layout_height="fill_parent"
android:gravity="center_vertical|right"
android:paddingRight="5dip"
android:paddingTop="22dip"
android:text="€"
android:textColor="#color/black"
android:textSize="35sp"
android:textStyle="bold" />
<TextView
android:id="#+id/topup_display_amount"
android:layout_width="90dp"
android:layout_height="match_parent"
android:gravity="center_vertical|left"
android:textSize="65sp"
android:textColor="#0d457f"
android:textStyle="bold" />
</LinearLayout>
And the pressed_topup_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:state_enabled="false">
<item android:state_pressed="true" android:state_enabled="true" android:drawable="#drawable/button_topup_glow" />
<item android:state_focused="true" android:state_enabled="true" android:drawable="#drawable/button_topup" />
<item android:state_enabled="true" android:drawable="#drawable/button_topup" />
</selector>
The LinearLayout is used to populate a GridView in each cell.
When i click the cell the behavior is correct (the glow is displayed) but also a yellow color is display on the corner of the image (where suppose to be transparent). How can i fix that?
Thanks
You need to add
android:listSelector="#android:color/transparent"
to your GridView declaration.
See this:
Android: Disable highlighting in GridView

Android ListView item blinks on selection

I am creating a custom ListView as below
Main Layout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ListView android:id="#+id/listview"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_margin="3dip"
android:fadingEdge="none"
android:soundEffectsEnabled="true"
android:clickable="true"
android:scrollbars="none"
android:divider="#ffcccccc"
android:dividerHeight="1dip"
android:layout_weight="1"/>
</LinearLayout>
Custom ListView
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/sellistitem">
<TextView
android:id="#+id/ListItem"
android:layout_width="wrap_content"
android:layout_height="30dip"
android:layout_margin="1dip"
android:textColor="#color/BLACK"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="5dip"/>
</RelativeLayout>
and Selector as below
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/BLUE" />
<item android:drawable="#drawable/WHITE" />
</selector>
The Drawable
<resources>
<drawable name="WHITE">#ffffff</drawable>
<drawable name="BLUE">#ff0033cc</drawable>
</resources>
Having done this the selection part works fine. However when I click on any item ,the selected item blinks twice before actually changing to blue. It doesn't change to blue directly as it should. How can I remove this blinking effect?
Regards,
try this android:cacheColorHint="#00000000" to listview
Selectors are tricky, in general. Try this for your selector instead:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_enabled="true"
android:drawable="#drawable/selected_background" />
<item android:state_focused="false"
android:state_pressed="false"
android:state_selected="false"
android:state_checked="false"
android:state_enabled="true"
android:state_checkable="false"
android:drawable="#drawable/normal_background"/>
</selector>
Note that the android:drawable attribute does not have to be a drawable. If it's a simple color you can reference it with the #color/background_color format.
EDIT:
Ok, those white and blue "drawables" aren't drawables, they're just colors, you're better off defining them in the colors.xml. It could be that that is actually the reason for the flickering.
<resources>
<color name="blue">#ff0033cc</color>
<color name="white">#ffffff</color>
</resources>

Categories

Resources