Junior222
Junior222

Reputation: 833

Custom TextView background

I would like to create TextView with custom baground such as

enter image description here

but unfortunatelly I have no idea how to do it. Maybe someone knows how to create the background in xml (not in java code)? Thank you in advance

Upvotes: 0

Views: 585

Answers (2)

Vyshnavi
Vyshnavi

Reputation: 338

Create a layout like this. You have to use the custom image for this. Your code goes here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="your_custom_image"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="20dp" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="text_goes_here"
        android:textColor="specify_color" />

</LinearLayout>

Upvotes: 0

Cory Charlton
Cory Charlton

Reputation: 8938

Use setBackgroundResource(int resourceId) in code or android:background in your layout.

Java:

mTextView.setBackgroundResource(R.drawable.yourDrawable);

Layout:

<TextView
    android:background="@drawable/yourDrawable"
    ...
    />

Upvotes: 1

Related Questions