Fixed: "Android: Detecting focus/pressed color" -


i'm trying detect focus/pressed color button , other elements. needed because i'm developing new components , it's important part of platform. colors orange on android sdk , green on htc senseui. if detect color component part of platform on both version.

does knows how this?


it's possible create "selector" uses custom image default state , platform default focus/selection.

to follow steps: 1) create xml file selector in "res/drawable" (e.g. "red_button.xml"):

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

2) folder ".../android-sdk-mac/platforms/android-1.5/data/res/drawable/" take picture "btn_default_pressed.9.png" , change color (i needed change red , gimp enough).

3) place altered picture in "res/drawable" (e.g. name "btn_default_red.9.png")

4) define button:

<button     android:id="@+id/info_button"     android:layout_width="wrap_content"      android:layout_height="37dip"     android:layout_margintop="1dip"     android:background="@drawable/red_button"     android:text="[info]" /> 

that's all.

this result: alt text http://img200.imageshack.us/img200/1349/custombutton.png

i had problem too. stated, problem backgrounds aren't simple colors, they're drawables take on kinds of appearances. however, found work-around may help. if custom component looks existing one, e.g. button or listview entry, can steal background/selector , set background custom component. e.g., in custom component constructor:

  setbackgrounddrawable(new button(context).getbackground()); 

or background more suitable list-like components:

  setbackgrounddrawable(new listview(context).getselector()); 

you may want optimise code somewhat, idea.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -