Android change imageButton when finger is hover on that - android

i'm create simple application to work with custom buttom if finger is pressed or released and hover on that. in this simple selector project have 4 state for change background image, but i need to change this button when finger pointer is focus or hover on that but that does not work and only press work correctly in my project.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="#drawable/logo"/>
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="#drawable/gohome" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="#drawable/goran" />
<item android:drawable="#drawable/logo" />
</selector>

In touch UI there is no such thing as "hover". Hover is when your pointer is over a control. Without having a pointer, you cannot reproduce this step.
You can play with "focused", "pressed" and default.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:drawable="#drawable/logo"/>
<item android:state_pressed="true"
android:drawable="#drawable/goran" />
<item android:drawable="#drawable/logo" />
</selector>

Related

Android Button onPress Color

I know this has been asked a nos of times but i am not able to change the button background color when pressed. Here are the codes. When the page is launched the button bg color is black but when i press it, it changes to green - probably it might be at code level which i have no access so i want to use the xml file configuration.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/black"/>
<item android:state_enabled="true"
android:state_pressed="true" android:drawable="#android:color/black" />
<item android:state_enabled="true"
android:state_focused="true" android:drawable="#android:color/black" />
<item android:state_enabled="true"
android:state_selected="true" android:drawable="#android:color/black" />
</selector>
and
<Button
android:id="#+id/payBtn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/button_background_selector"
android:onClick="onPayPressed"
android:text="#string/pf_pay_btn_hint"
android:textColor="#android:color/white"
android:textColorLink="#android:color/white"
android:textSize="#dimen/pf_20_txt_size" />
Button button = findViewById(R.id.loginbtn)
button.setBackgroundColor(Color.parseColor("#555555"));

Define drawable for CheckedTextView for checked and pressed state in Android

I have current code
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="true"
android:drawable="#drawable/list_button_selected" />
<item
android:state_pressed="true"
android:drawable="#drawable/list_button_pressed" />
<item
android:drawable="#drawable/list_button" />
</selector>
for my CheckedTextView and it works. But when it's checked and I press on it, it shows default android color for background. How can I overwrite that? I tried
<item
android:state_checked="true"
android:state_pressed="true"
android:drawable="#drawable/list_button_selected" />
But it does not work.
In my case, order is important. I had to switch checked and pressed and its working now.

Button always displays with first listed style in state list drawable no matter its state

Long time stackoverflow reader, first time with a question. The problem I am having seems silly, but I can't find any information that explains it.
I am new to Android programming and am working on a project with custom button backgrounds. I am using state list drawables for the different buttons that look like this:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="#drawable/button_pressed_background" android:gravity="center"/>
android:state_pressed="true"
</item>
<item>
<bitmap android:src="#drawable/button_focused_background" android:gravity="center"/>
android:state_focused="true"
</item>
<item>
<bitmap android:src="#drawable/button_standard_background" android:gravity="center"/>
android:state_pressed="false"
android:state_focused="false"
</item>
</selector>
In the xml where the buttons are declared, I simply add the line android:background="#drawable/button_drawable" where button_drawable.xml is the state list drawable.
Seems simple enough, but in all cases, the buttons display with the background listed in the first <item> section of the state list drawable, no matter their state. In fact, in the example above, I could change the first <item> section to include android:state_pressed="false" instead, and the button_pressed_background still displays! It is as if all button states are true and false simultaneously.
I am developing using emulators, but see this behavior both with the AVD emulator and with Android x86 running on Oracle VirtualBox. Any idea why this would occur?
Define a selector with the below code and try it as background:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true" android:drawable="#drawable/background_sel"/>
<item android:state_focused="false" android:state_pressed="true" android:drawable="#drawable/background_sel"/>
<item android:state_focused="true" android:drawable="#drawable/background_sel"/>
<item android:state_focused="false" android:state_pressed="false" android:drawable="#drawable/background_normal"/>
</selector>
Itz not android:src, its android:drawable
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/btn_new_default" />
<item android:state_pressed="true"
android:drawable="#drawable/btn_new_default_pressed" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/btn_new_default" />
<item android:state_enabled="true"
android:drawable="#drawable/btn_new_default" />
For more action get the original file from
drive letter:\android-sdk-windows_new\platforms\android-8\data\res\drawable\btn_default.xml

question about change the colours of a button when clicked

My purpose is to change the color of a button when click and my codes are
<?xml version="1.0" encoding="utf-8"?>
selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="#drawable/btn_askering_active" android:state_selected="true" />
<!-- When not selected, use white-->
item android:drawable="#drawable/btn_askering" />
</selector>
It works but if i make a small change like below :
xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When not selected, use white-->
item android:drawable="#drawable/btn_askering" />
<!-- When selected, use grey -->
item android:drawable="#drawable/btn_askering_active" android:state_selected="true" />
</selector>
It does not work anymore....
I need some help...Any comments are welcomed here.Thanks
I think you need to mention stats in selector like pressed or focused and change image accordingly.
Here i have attached sample selector file,have a look and try accordingly.
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false"
android:drawable="#drawable/estimator_hover_new" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="#drawable/estimator_hover_new" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="#drawable/estimator_hover_new" />
<item android:drawable="#drawable/estimator_new" />
</selector>
All The Best....

How do I get the android icons to change state (highlights)?

I am using the Android SDK icon-button for refresh (ic_menu_refresh) in a widget and I need to change the selection state when it is pressed. How is this done? Do I define an XML for the button?
You define the different states in xml via selector.
Sample (esp. see the state-attributes):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/bg_catlocfilter" android:state_pressed="false" />
<item android:drawable="#drawable/bg_catlocfilter_dark" android:state_pressed="true" />
<item android:drawable="#drawable/bg_catlocfilter" android:state_focused="false" />
<item android:drawable="#drawable/bg_catlocfilter_dark" android:state_focused="true" />
</selector>

Categories

Resources