What are the Material Design Guidelines for ImageButtons? - android

What do the Material Design Guidelines say about ImageButtons (not toggle buttons)?
I cannot find anything about them here: https://material.google.com/components/buttons.html.
How should they look?
When should they be used and when?
How should they behave?
Example: I have navigation buttons left/right to switch through days and I wonder if they are conform with Material Design.

Found this from source of Decompiled ImageButton class.
Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular {#link android.widget.Button}, with the standard button
background that changes color during different button states. The image on the surface of the button is defined either by the {#code android:src} attribute in the {#code } XML element or by the {#link #setImageResource(int)} method.
To remove the standard button background image, define your own background image or set the background color to be transparent.
To indicate the different button states (focused, selected, etc.), you can define a different image for each state. E.g., a blue image by default, an orange one for when focused, and a yellow one for when pressed. An easy way to do this is with an XML drawable "selector."

Related

Android: Why is the button color in my widget different thhan in main activity?

I'm just learning Android development, trying to wrap my head around styling (with Material styles).
In my main app, I have a button that's a nice purple color. I didn't assign it any styles, I just dragged it onto the view. The background of my app is dark (because of my system settings). The material styles are listed as a dependency in the App-- when I create a normal button, do I need to assign it styles manually, or does it automatically become a material button?
I'm further confused by this because I created a homescreen widget (currently just a button in a relative view with no background on the view). It isn't purple, unlike the other button. It's just grey.
tl;dr; What accounts for the difference in the button colors between my main activity and homescreen app? The XML for both of the buttons is identical.

Material Color Reveal via Radial Reaction

In Android, a feature called radial reaction exists (find it at https://material.google.com/motion/choreography.html#choreography-radial-reaction).
After a bit of research, I discovered that we can use this to reveal views (see http://android-developers.blogspot.com/2014/10/implementing-material-design-in-your.html and http://pulse7.net/android/android-create-circular-reveal-animation-and-ripple-effect-like-whatsapp/).
Is it possible to reveal a certain color, instead of a view? (For example, change the background color to red when the user clicks the layout)
For now, only revealing a view is supported out-of-the box in ViewAnimationUtils https://developer.android.com/reference/android/view/ViewAnimationUtils.html
You could have your layout file define two different background layouts (LinearLayouts for example). The circular reveal would reveal whichever view you need.

How to create arrow type layout?

I have start and end date time fields that look like in picture below. Blue color shows active selection - if we select right then blue color goes to right and white color appears on the left and vice versa.
Hardest part is to create that arrow style in the middle. What should i use because buttons are rectangles and I don't know how it could be done.
It's easy. Just use ninepatch.
You can start there:
http://radleymarx.com/blog/simple-guide-to-9-patch/
you need a custom image according to what you ask, maybe extend ToggleButton for that but basically what you want is the same component when pressing on two different places on the same component will dispatch different events.
I would for example extend Linear layout, make it vertical layout, put two clickable textView\buttons with 9 patch images as background ,like suggested before, one for the white part and the other for the blue part. and replace the background image for any event u like.
you can also create a StateListDrawable with actions for selected and deselected and set the state of each drawable upon the right click

Android Button drawable issue

I'm trying to achieve buttons similar to the icons in the Action Bar, i.e. transparent images that change background colour on click.
These are the conditions I'd like to satisfy:
Background colour changes on click
Contains a small rectangle shape in the center
Rectangle can change colour programmatically
I tried using a Drawable to represent the rectangle and then to set it as the background of the button, but it expanded to the edges of the button and so there was no background colour to change when clicked (I was able to use drawable.setColorFilter() and button.setBackground(drawable) to alter its colour however). Shrinking the button also shrank the touch-target.
I also tried using a StateListDrawable containing two rectangle shapes, a background and an inner rectangle, so on state_pressed the background rectangle would change colour. However the front rectangle stretched again and completely covered he background rectangle.
Which method can achieve my conditions? Thanks.
Have 2 images for the state of the buttons and use this:
boolean clicked = false
Button btn = (Buttton)findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
if (clicked)
{
clicked = false;
btn.setBackgroundResource(R.drawable.button_image_on);
}
else
{
clicked = true;
btn.setBackgroundResource(R.drawable.button_image_off);
}
}
});
This talk from Google IO 2013 on Android UI design by Nick Butcher and Roman Nurik helped to solve the problem.
The XML attribute style="?android:borderlessButtonStyle" can be set on an ImageButton (or even just a Button) to give it a transparent background which lights up in a standard Holo blue colour on touch. According to Roman Nurik, this attribute provides the standard styling "all for free".
I created an ImageButton containing that borderless button attribute in my layout.xml file, then I created my coloured Drawable in Java and put it inside the button using myImageButton.setImageDrawable(myColouredDrawable); to fit all three of my conditions.
Edit July 2013: To bring the ActionBar pattern to older versions of Android using Jake Wharton's ActionBarSherlock, use style="#style/Widget.Sherlock.ActionButton", or if using the ActionBarCompat Support Library, use style="#style/Widget.AppCompat.ActionButton"
Update May 2017: For ImageViews (I believe it is actually an ImageViewCompat) I am using android:background="?android:attr/selectableItemBackground" on Jellybean onwards.

Android ImageButton push color

I have an ImageButton that I switch the images when pushed. The problem is that the animation tints the button blue when I push the button between my two image switches. How to I prevent that blueish tint from animating? Also, how do you do it programatically and not through the XML.
Well for most use cases, you should be using XML... but lecture aside, the blue background is part of a StateListDrawable that is set by default as your button's background. Defining and setting your own background (via setBackgroundResource(int resId) or similar) should be sufficient to "get rid" of the focused color state.

Categories

Resources