creating an "elevated button" effect in android - android

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.

Related

Easy way to change Firemonkey button pressed color on Android

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.

Android ImageButton - How to hide the image while showing the background?

I've read the API and Googled but perhaps I've missed something: All the visibility options on an ImageButton seem to talk about this view as a whole. So, what should I do if I want to hide the image but keep the background(except for explicitly setting the image to something transparent that is)? I'm doing a Pairs Game and when one clicks on the element it should show the image and if the next click doesn't match the image should be hidden, but the grey background of the button should remain.
Thanks!
So, what should I do if I want to hide the image
Try setting it to #null or create transparent PNG in your drawables and set it.
in XML, remove android:src="something" and in the code remove imgbtn.setImageBitmap(null);
Instead of using ImageButton you can use ImageView with a FrameLayout on top of it. Set the background of FrameLayout as gray color and then show/hide this FrameLayout/Image as per your requirement. Take relative layout for each and make it clickable. On the click event of this layout, do the changes as required.

how to click Background and something should happend?

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.

Android, dynamically adjust the z-index of a button?

I have 5 buttons on my activity. When a user touches any of them, the button will play an animation which is roughly twice the size of the button itself. When the active button grows/animates, it will overlap the non-active buttons...and sometimes be hidden behind (usually on the edges)
Is there a way I can dynamically adjust something similar to z-index for the button in animation? I already have the logic set up, just don't know the name of a function/if it exists to do this.
Thanks!
Try using bringChildToFront() on the surrounding Layout.

Button with background, no cursor

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

Categories

Resources