what is use of image button? - android

I'm new to Android application development.
I would like to ask the use of image button in Android programming when simple button can also add the image with the button. How can we generate click event of image button?

The Image Button control is a special type of button that displays a Drawable graphic instead of text.
The Image Button and Button controls are both derived from the View class, but
they are unrelated to each other. The Button class is actually a direct subclass
of Text View (think of it as a line of text with a background graphic that looks
like a button), whereas the Image Button class is a direct subclass of Image View.

If you will look in the API for Button you will see that it has a method called setOnClickListener that is inherited from View. Since ImageButton is also a view, you can also call the same method for it.
The only way that I see to use an image in a Button is by using android:background in the XML. This is only used for setting what's shown behind the text of a button. You should use ImageButton when you want to make a button that only uses the image as its defining feature. If you end up wanting to only see the image and have no part of the button background visible, you can set android:background on the button to use an invisible Drawable.

Related

Create animation of image on button

I am trying to create a library for android basically it's a indeterminate progress bar on button itself and even text next to it look the pic for reference it is inspired from snapchat
So basically i need a button with icon and text and the icon should perform animation on the button itself
I tried using drawableLeft but i can't perform the animation
I also tried using linerlayout with imageView and textView inside it in xml and then perform animation on imageView but since i am creating lib all i want is in a class file
So any suggestion or idea how I can solve the problem?

how to have string and image as a content of a button

I have a button in which I set its background a to 9 patch drawable and I set the text to some value. All works well. Now I want to add an image with the text (so text and image inside the button).
How can I do that?
Thanks
You can use styles in your button layout xml.
style="#style/settingTextView"
This will turn your button to the buttons you see in the settings APP. Then you can add left and right images to your button. Using -
android:drawableRight="#drawable/some_image_right"
android:drawableLeft="#drawable/some_image_left" android:text="#string/button_text"

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 create an iOS style arrow button in Android?

I am partial to dual use buttons in iOS, like in the image below:
How can I create these types of buttons in Android? In other words, the entire button must be clickable, the arrow must be right-aligned and the text of the button must be left aligned.
I tried playing with a regular Button widget, but no luck. Do I have to resort to a Table layout (but then the clickability would be lost).
You will need customized shape background for the Button
You can find customizing shape here.
Set that background to the Button from xml, and for showing arrow, you will need to add arrow.png to your project drawables.
you will add attribute to button like this:
<Button android:backround="#drawable/cell_background"
android:drawableRight="#drawable/arrow" ... />

Push button effect with Imagebutton

I have been working on an app, which basically consists of imagebuttons.
I want to achieve the push button effect with imagebutton.
Is it possible to achieve..
you can programmatically do using setColorFilter or setAlpha (it depends on the effect you want) to your buttons when you do some action (in this case i suppose onPress).
These are methods inherited from ImageView:
ImageView Reference

Categories

Resources