How can I set layout_gravity dynamically in android? - android-layout

How can I set layout_gravity programmatically?
I need to set position of a button LEFT or CENTER or RIGHT in a particular layout, I used the myButton.setGravity(Gravity.LEFT); but, it sets the gravity of button's text.

I found this by putting your title in the search bar. The short version: Use LayoutParams

Related

tvOS button background color issue where it's not set properly

As you can see, I'm trying to set the button's color to a very light blue, but by default everything but the bezels are being darkened. Is the default button behavior causing this? Is there a workaround besides creating your own button? If I do have to create my own button, how can I reuse the default button's animation behavior? Thanks.
You don't have to create a custom button.
Instead, create an image containing the color you want and use that as a background image. Plus make sure to set the button's background color to default (clearColor), otherwise you will lose the rounded corners.

Android UI: Button with shape inside?

I need to create a button that looks like this:
button
I was hoping to create it without using images. To create the pink part, I wanted to use a drawable.
How can I include a shape drawable within a button?
You can create a Layout, set background color for that layout as you wish. In that layout add two textviews. Set background for one layout pink. add another under the first textview. Then you can set onClickListener on layout. It'll work same as that of button and it'll be easy to change colors and text programatically.
Try using an ImageButton and setting android:src to point to your ShapeDrawable resource.

Change command menu background in LWUIT

Can we change Command's background color of the menu in LWUIT ?
and how can I set an icon to the "Menu" generated Command ?
thanks
I will try to explain better than the other post. You can change the style of the Menu using and UIID.
There are two ways to do that.
Easy way. Use the LWUIT Resource editor and create in the Unselected tab, and UIID called Menu. In this UIID you should configure the background color as you wish. You can change more things (like text color, size of the font, etc)
Hard way, by code. Create a Style object and set it to the Menu.

I cannot center the text of a userdefined Button

I created a Button and I set its UIID to boutonPpal. I set the bgAlign attribute to ALIGN_CENTER in the resource Editor but the text of the Button is not centered at runtime !
So how to make the text centered ?
bgAlign aligns the background image of a component. Use the "Align" tab if using the latest LWUIT. If you are using 1.4 you need to actually invoke setAlign() on the component since in 1.4 alignment was not a part of the theme.

Add image to the form title

I have a Form. It is scrollable
And I need to have an image, that must always be at the top part of the scrreen.
How can I do that?
(I can set text to the title, but not the image)
if you are using lcdui Form, then you can't. If you are using LWUIT form, you can set an icon to a label then you can set this label as a title to the form via setTitleComponent(Label label).

Resources