I'm trying to customize my buttons in my view a bit and give them my own look. Whenever I set a picture as a background so that the button looks different though, I seem to lose my cursor. I can use my trackball to go through the items still but when I come to one of my custom buttons the cursor does not show. I have the same problem with some TextViews that I made clickable. Any ideas?
(this is a button which i am trying to give a custom look by giving it a background. when i give it a background though, the cursor does not show when it is over it.)
Your background drawable needs to be a state list drawable (or selector) so that you can provide a background image for the focused state. Take a look at the default background drawable used by buttons on Android:
https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/drawable/btn_default.xml
Related
I want to click the Background of a layout (not clicking anywhere, for example in the top right) and then reproduce a sound, can i put an empty View and put an On Click to that? I think is not possible.
If is possible, there is a better way?
I want to put some invisible "buttons" at the Background because I will put an image Background with shapes, that's why It couldn't be anywhere.
Thanks and sorry for my english.
You can put a button on the right corner and apply an empty or simply transparent image as icon button.
In this way, you can choose a different behavior for each screen position.
I want the button to appear as though it has space in between the bottom of it's face and the canvas. Then, when clicked, it will appear as though there is no space between the button and the canvas. I know I can style the button with xml to give it those 2 looks but I don't know how to do the elevated look.
My question is how would one go about doing this?
Easiest approach to this is creating 2 background images, each fitting the state you want, then you can either set the backgrounds according the button's state, or change the backgrounds by setting an onTouchListener to the button.
I am using the same background shape in a layer list for each button, then in that layer list a specific image related to the function of that button.
I know that I can create a selector for each button, however is there any way to reuse a selector and dynamically change the image (normal, focused and pressed all use the same image) for each button?
Even if there is no way to reuse a selector, are there any other good approaches for reuse and as opposed to creating 3 separate layer-list drawables and a selector for each button?
Cheers
EDIT: The button each have a text component
use ImageButton
android:background="#drawable/yout_selector"
android:src="drawable/image"
I am using a button with my own back ground color in android and that button is not getting focus what is the problem?
Buttons normally will not have focus by touch. Also focus depends on the background.
So, check the background - it needs to be of type drawable with multiple states or you need to make a gradient. Check Standard Android Button with a different color
I'm changing the background drawable for my buttons when they're clicked (as they trigger functions such as play/record). While playing/recording, the button glows (a different 9-patch is set as the background) and turns into a stop button. My problem is that currently I'm using:
b.setBackgroundResource(R.drawable.btn_default_normal);
to set the background back again afterwards. This works, but the normal behaviour when I use setEnabled(false) is lost. After a button has been used, and reset to normal, it retains the normal background (rather than the dimmed one) when disabled. The text still changes colour though. Is there a way of 'resetting' the background of the button to default, so that it retains its normal behaviour?
Ok, I got the answer from this blog post in the end. What you have to do is create an xml document with all the different button states, and assign that rather than just an image to the background.