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

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"

Related

How I will set background of a button on android with kotlin

I can not use bitmap as background of a button on android with kotlin
Go to you app's layout file. Make sure you are on the Design tab. Click the button and look at it's attributes on the right-hand side. Then click the search icon in the attributes. Type in background on the search bar. You will see a background attribute. Click the Pick a resource button on the right-hand side of the background attribute(it's on the same line). Select your desired background for your button.
Hope it helps :)
In Activity:
Button11.setBackgroundColor(getResources().getColor(R.color.red));
When not in Activity:
Button11.setBackgroundColor(Button11.getContext().getResources().getColor(R.color.red));
For full customized color:
Button11.setBackgroundColor(0xFFFF0000);
For setting a bitmap
Button11.setBackground(yourBitmapObject)

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 yo add glowing effect on button with background?

I have taken a button in my xml and set its background img1 now on the click of that button i want white glow around that button edges . I have refereed this links http://developer.android.com/guide/topics/ui/controls/button.html Android ImageButton with a selected state? Standard Android Button with a different color
You can add a white border to the button. please enter this question to see how to add border: Android - border for button
Store the xml in
res/drawable/filename.xml
And then you can access it like this:
In Java: R.drawable.filename
In XML: #[package:]drawable/filename

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" ... />

what is use of image button?

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.

Categories

Resources