10

I want to create a TextView which has a custom background. In particular I would like to have a Text view which looks like this. I know that i can set a background to a TextView with android:background="@drawable/displaybackground but how can i align the text in this textview. The text should be displayed in the center of the Textview, like in the image above.

kind regards

Community
  • 1
  • 1
Moonlit
  • 5,171
  • 14
  • 57
  • 95

3 Answers3

32

Use center for the gravity property in the TextView (not the layout_gravity).

Mickäel A.
  • 9,012
  • 5
  • 54
  • 71
M.Sameer
  • 3,072
  • 1
  • 24
  • 37
6

Here you are. You just have to find the background, that you like.

<Textview
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:gravity="center_vertical|center_horizontal" //center the text horizontally, and vertically
    android:text="You place your text here..." // Text inside the TextView
    android:background="background Here"/> // Background (drawable or color)
ya-ivanov
  • 516
  • 2
  • 11
0

find below link for that:

How do I center text horizontally and vertically in a TextView on Android?

Good Luck :)

Community
  • 1
  • 1
Ripal Tamboli
  • 562
  • 1
  • 4
  • 16