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

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)

Related

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.

What is the best UI design for picking object icon in Android?

I have an Activity which provides UI for editing entity properties such as name, description an so on. This entity can also have an icon but (this is the main problem) can have no icon. I have created an icon picker activity which provides UI for icon selection. But I can not think of a simple and pretty way to provide access to this picker from parent activity. It could be a simple image button if the task was just to select an icon but I have also to make it possible to remove already set icon. Having two buttons with 'choose' and 'remove' seems ugly. Any smart ideas?
UPDATE
I've ended with ImageButton showing selected icon or special 'No' icon if object has no icon. On button click I show PopupMenu on 3.0+ and ContextMenu on older versions. Menu contains 'Change' and 'Remove' items.
You could have a border that surrounds an empty space or the image if there is one already.
If the image exists, clicking on it brings up a dialog where you can choose to change it or remove it.
If it doesn't exist, clicking on it brings up a dialog where you can add it.
how about a gridview within a custom dialog fired from your parent activity??
change the icon onItemSelected() of the gridview??

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

Android: How to do create custom EditText with a clickable arrow on the right

I would like to have an EditText with one modification: on the right but still inside the EditText there should an arrow pointing downwards that I can set OnClickListener to so that when the user clicks on the arrow it displays a menu.
What is the best way to do this?
Do you mean something like this ?
see image
Add the arrow by setting the drawable right attribute
android:drawableRight="#drawable/right"
to your EditText. Then you would need to set an OnTouchListener to get the events.
I did this by putting EditText and a Button into RelativeLayout, the Button (which has custom background drawable) is overlapping the EditBox.
When user clicks on it, the EditBox doesn't receive the click event.
Sounds like a combo box. If you look at the "Building Custom Components" section of the Dev Guide, they mention combo box briefly, but give details on how to build any custom component.

Categories

Resources