Galip
Galip

Reputation: 5455

Change selection color on Button's and TextView's in Android

I'm developing an app and when I run it in the Emulator and I've selected a button (not clicked!) it shows an orange layer over it. When i click it i turns yellow. On a HTC device the orange/yellow overlay is green. On a Samsung Galaxy S it's blue.

I want my app to have the same selection color's throughout the whole app (Blue to be precise).

Is this possible? If so, how?

Upvotes: 3

Views: 4930

Answers (4)

Shahid Pasha
Shahid Pasha

Reputation: 81

Create a selector in your drawable folder for example drawable/item_selctor.xml

<?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/item_button_selected"
          android:state_pressed="true" />
        <item android:drawable="@drawable/item_button_selected"
          android:state_focused="true" />
        <item android:drawable="@drawable/item_button_selected"
          android:state_selected="true" />
       <item android:drawable="@drawable/item_button" />
     </selector>

In your code or xml file use

 item.setBackgroundResource(R.drawable.item_selector);

in code or

android:background="@drawable/item_selector"

in xml layout file

Upvotes: 0

Parag Chauhan
Parag Chauhan

Reputation: 35946

You r right

But u also set background color at runtime

& Another

possibility that may be HTC /Samsung has different Android Version ?

so this Happen

Upvotes: 0

Nikki
Nikki

Reputation: 3318

I think link provided below could be helpful for you

link is: http://groups.google.com/group/android-developers/browse_thread/thread/a7ff938ce09e7c37

Upvotes: 2

Peter Knego
Peter Knego

Reputation: 80340

Yes it is possible. Use Themes to apply style to the whole app.

Upvotes: 1

Related Questions