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
Related
This might be one of those forehead-slapping questions, but what I want to do, is make my buttons show orange (xFFFCB447) when they are pressed, just like the Android dialogs do. (picklist for example)
There doesn't seem to be a specific "pressed" TRectangle in the Default Style, and my adding different TRectangles (coloured appropriately doesn't seem to do it either), so my only alternative seems to be to use the Bitmap Style designer to Export the style.png; hope I figure out which part of the image is used for the button pressed before tomorrow afternoon, and Update the image again.
Is there not an easier/quicker way to do it?
Option A) Drop a TRectangle on your button. Set it's Align to Contents. Set it's fill color to Orange. Set it's Opacity to 0.50. Set it's HitTest to False. Set it's Visible to False. In the TButton.OnMouseDown set the TRectangle Visible to True. In the TButton.OnMouseUp set the TRectangle Visible to False. You will also need to set the OnMouseMove of the control that TButton is on to set TRectangle Visible to False as well so if you mouse down and then move away it will be hidden as well.
Option B) Drop a TFillRGBEffect on the TButton. Set it to Orange. Do the same as above to enable and disable the effect on mouse down and up. However, be aware that TFillRGBEffect may be slower than the TRectangle way.
Option C) Just use a TRectangle instead of a TButton. Put a TText or TLabel inside it for the text and align to Contents. Change it's Fill color in OnMouseDown and OnMouseUp.
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 use setEnabled on RadioGroups, EditText, Spinner, and Checkbox. However when I do so the data is very dark to see (have to squint at it). How do I make it so that the disabled controls can be viewed easily by the user AND have it differentiated from the editable mode controls.
You would have to provide the drawables for the background of each control. You'd probably want to implement a selector to change the image based on the state.
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.
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