Android Question ToggleButton Text Gravity

Firpas

Active Member
Licensed User
Longtime User
Hi to everybody

Is posible to set text gravity in toggleBtutton??

I am trying this code to do a graphic togglebutton but text style vertical alignment not work:

B4X:
Dim PnlHome_BtnBt As ToggleButton

Dim BackBtnBtOn, BackBtnBtOff As BitmapDrawable
BackBtnBtOn.Initialize(LoadBitmap(File.DirAssets, "pnlhome_btnbton.png"))
BackBtnBtOn.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.TOP
BackBtnBtOff.Initialize(LoadBitmap(File.DirAssets, "pnlhome_btnbtoff.png"))
BackBtnBtOff.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.TOP
Dim BackBtnBt As StateListDrawable
BackBtnBt.Initialize
BackBtnBt.AddState(BackBtnBt.State_Checked, BackBtnBtOn)
BackBtnBt.AddState(BackBtnBt.State_Unchecked, BackBtnBtOff)
PnlHome_BtnBt.Background = BackBtnBt
PnlHome_BtnBt.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.BOTTOM

As you can see the attached image, also I set the property in the designer, but does not work properly.

Is there any solution?

Thanks in advance
 

Attachments

  • ScreenShot1.png
    76.8 KB · Views: 308

udg

Expert
Licensed User
Longtime User
Hi Firbas,

try the following:
B4X:
BackBtnBtOn.Gravity = Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.TOP)

udg
 
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
Thanks for yor answer.

Bitmap.gravity is correct, the questios is text.gravity

Bitmaps.Gravity must be Top and Center and it is ok.

Text Gravity must be Bottom and Center and it is not ok.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Apply same suggestion as above.
B4X:
PnlHome_BtnBt.Gravity = Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.BOTTOM)
Gravity is an integer made up of two parts, the vertical and horizontal alignments.

udg
 
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
Ok.

I think my problem is the led on togglebutton.
The text does not align down like a button
 
Upvote 0
Top