I have some EditText
and TextView
inside a Fragment
. On the XML layout of the fragment I have added the following in EditText and TextView:
android:textAlignment="center"
Then I have tested the app in the emulator, on virtual device with API 25
, and all seems to work fine, the fragment is displayed as it looks in the design window, with the text centered in both the EditText and the TextView.
However, I have launched the app in my own phone Android 4.1.2 API 16
and also in another virtual device that I have also created with API 16
and now none of the 'EditText' or 'TextView' are respecting the textAlignment
property, the text is just displayed aligned to the left side.
Any help?, I am looking around but I cannot find anything related to API 16 and problems like that with alignments.
You should use
android:gravity="center"
Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
You can easily do that with below. As i mentioned in comment also.
<EditText
android:id="@+id/et_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ems="10"
android:gravity="center"
android:hint="Bio DAte aaaaaaaa"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLines="3"
tools:ignore="RtlCompat" />
Check official documentation .
android:textAlignment="center"
or its setter were introduced in API 17. So it won't work on earlier devices ie API 16.
Instead use android:gravity
which should provide the same functionality both in EditText
and TextView
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.