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:

Code:
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

Hi Firbas,

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

udg
 
Upvote 0
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
Apply same suggestion as above.
Code:
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
Ok.

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