How to change button background as a progress? - android

I'm trying to change the background of a button as a "loading" while it's pressed, but I'm not sure how to make.
First I tried to use a progress bar but, what I want is to load the background progressively if the button is pressed or revert it if the button is released.
Thanks in advance for any idea.

Set the button background to a selector, such as this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/loading" android:state_pressed="true" />
<!-- pressed -->
<item android:drawable="#drawable/normal" android:state_focused="true" />
<!-- focused -->
<item android:drawable="#drawable/normal" />
<!-- default -->
</selector>
That should change the button background as you press and release the button.

Related

Button change color

I have two buttons in layout,let suppose button A and button B and I want that when user touch any of two button,their background color should change for that moment.
code
``
<item android:state_hovered="true"
android:drawable="#drawable/state_hovered"/>
<item android:state_pressed="true"
android:drawable="#drawable/state_pressed"/>
<item android:drawable="#drawable/state_deafult" />
``
State_pressed working...but state_hovered is not working.
So,please suggest a way to do so.
Thanks in advance.
Change color while button is pressed?
See an answer to this question, asked previosly in StackOverflow:
Create a my_button_background.xml file 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="#color/blue" />
<item android:state_focused="true" android:drawable="#color/gold" />
<item android:drawable="#color/grey" />
</selector>
And use this in layout file:
android:background="#drawable/my_button_background"
And read more about Android's Color State. Basically, you can assign colors, drawables, shapes, etc. to different states of views, such as enabled, disabled, focused, clicked, etc.

How can add imagebutton click effect?

I am working with android. I want to add onClick() effect on ImageButton preferably a color around the sides of the button after selected. I had tried with alpha effect.But It looks dark even after get back after click.
How can add ImageButton click effect?
you can use a selector xml like as follows :-
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_pressed_yellow"
android:state_pressed="true" />
<item android:drawable="#drawable/button_focused_orange"
android:state_focused="true" />
<item android:drawable="#drawable/button_normal_green" />
</selector>
and set it as a background of your Button.

Android ImageButton background change when clicked

I have an image button that has a transparent background and a image as a foreground. What i want to do is to make the button flash when i press the button. Now i don't want to define two different images for the up and down state, is there any why i can define a selector color for the background and foreground and the background of the button ?
Kind Regards,
You can use this code for background selection of button for diff-2 state of button, save this file in drawable folder and set button background. Hope it will useful to you...:)
<?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/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="#drawable/button_focused" /> <!-- focused -->
<item android:drawable="#drawable/button_normal" /> <!-- default -->
</selector>

Android:Styling ListView

I want to put some style in the ListView in such a way that when an item of ListView is hovered, the color of that list item changes. I dont have any idea about how to achieve this.
Please suggest some other ideas about styling the ListView as well.
Regards,
Use selector to define what should happen when you focus the item, select the item and press the item, I doubt you cannot hover over a view, since Android devices use touch screen interface and not a pointing interface like a mouse..
This should help you:
Create a XML file in drawable folder named listselector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="#color/blue" /> <!-- focused -->
<item android:state_focused="true" android:state_pressed="true" android:drawable="#color/blue" /> <!-- focused and pressed-->
<item android:state_pressed="true" android:drawable="#color/green" /> <!-- pressed -->
<item android:drawable="#color/white" /> <!-- default -->
</selector>
Then set the background of your TextView which you use in ListView to this like
android:background = "#drawable/listselector",
that should do it.

Does Android home screen widget support background selector in a TextView?

I have a TextView in my home screen widget. Can I use the following selector as the background of the TextView so the TextView can be highlighted when clicked? I know I can do it in Activity, but I am not sure about home screen widget. Thanks.
<?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/button_selected" /> <!-- pressed -->
<item android:state_pressed="false"
android:drawable="#drawable/beige_button" /> <!-- not pressed -->
<item android:drawable="#drawable/beige_button" /> <!-- default -->
</selector>
You can do this, if your TextView is clickable.

Categories

Resources