0

Android.Views.Textalignment is not working dynamically

I have tried the below code:

In load time:

CheckBox checkBox = new CheckBox(this);
checkBox.TextAlignment = Android.Views.TextAlignment.ViewStart;

Dynamically change the alignment in a button click. But alignment not updated.

checkBox.TextAlignment = Android.Views.TextAlignment.Center;
Phantômaxx
  • 36,442
  • 21
  • 78
  • 108

2 Answers2

0

I assume that you want to change the alignment of the text in the CheckBox. This can be achieved by setting the widget's gravity to center in through code.

checkBox.setGravity( Gravity.CENTER )
Shubham Panchal
  • 2,842
  • 2
  • 6
  • 22
0
        <CheckBox
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:text="Check Box"
            android:gravity="center"
            android:textAlignment="center"/>

make sure to use the width as match_parent ,
or a fixed size creater than the size of the checkbox text,
then you can use the textAlignment as center or anything you want

Samer Kasseb
  • 334
  • 3
  • 10