Change the progress of a search program

In my application, I have a search bar that should have two states - focused and normal

Not to make progress, I set a normal image in xml like this:

And here is the xml that I use to make progress

bar_normal.xml

<item android:id="@android:id/background" android:drawable="@drawable/black"/> <item android:id="@android:id/secondaryProgress"> <clip android:drawable="@drawable/black" /> </item> <item android:id="@android:id/progress"> <clip android:drawable="@drawable/grey" /> </item> 

Now that the user is touching this arrow, I want to change the progress to become orange.

I use another xml for this, and in my code I write like this

seekBar.setProgressDrawable (GetResources () getDrawable (R.drawable.bar_focused).);

bar_focused.xml

 <item android:id="@android:id/background" android:drawable="@drawable/black"/> <item android:id="@android:id/secondaryProgress"> <clip android:drawable="@drawable/black" /> </item> <item android:id="@android:id/progress"> <clip android:drawable="@drawable/orange" /> </item> 

Initially, the panel looks just fine, with the progress shown in gray and the background, and the secondary progress in black, but when I touch the search button to make it orange, the entire bar turns black. His work remains beautiful, but I do not see the orange color.

Please, help!

+1
source share
1 answer

you should not change the extraction using state, let Os do it for you, the default drop-down search template for Android:

  <item android:state_pressed="true" android:state_window_focused="true" android:drawable="@drawable/seek_thumb_pressed" /> <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/seek_thumb_selected" /> <item android:state_selected="true" android:state_window_focused="true" android:drawable="@drawable/seek_thumb_selected" /> <item android:drawable="@drawable/seek_thumb_normal" /> </selector> 

Ps: it makes no difference if you crossed out the image or defined in xml for your case, it should be (bar_drawable.xml):

 <item android:state_pressed="true" android:state_window_focused="true" android:drawable="@drawable/bar_focused" /> <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/bar_focused" /> <item android:state_selected="true" android:state_window_focused="true" android:drawable="@drawable/bar_focused" /> <item android:drawable="@drawable/bar_normal" /> 

0
source

All Articles