-1

I just want to give the same background to my both text view.

My code is :

<TextView
    android:layout_width="200dp"
    android:background="#f3f3f3"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="192.00 $"
    android:paddingLeft="4dp"
    android:textSize="36sp"
    android:id="@+id/textView"
    android:layout_marginTop="50dp"
    android:layout_below="@+id/imageView"
    android:layout_centerHorizontal="true" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="Recharge Limit"
    android:id="@+id/textView2"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true" />
swiftBoy
  • 35,607
  • 26
  • 136
  • 135
Abhishek Bhardwaj
  • 1,164
  • 3
  • 14
  • 39

3 Answers3

0

As you mentioned in comments your second Text View is below to first one. So you can put both Text View in Linear Layout view with orientation vertical and set background to Linear Layout so that both Text View will have same color.

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#f3f3f3"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="192.00 $"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="36sp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:text="192.00 $"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="36sp" />

</LinearLayout>

Hope this help.

Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
Neha
  • 245
  • 5
  • 17
0

Declare your color in res/values color.xml

 <color name="bg_tv_color">#f3f3f3</color>

and in your Text View tag add.

android:background="@color/bg_color"
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
Nouman Shah
  • 534
  • 1
  • 9
  • 22
0

You can custom style for text view <style name="TexViewStyle" parent="TextAppearance.AppCompat"> <item name="android:background">@color/colorPrimaryDark</item> </style> and use in text view `

<TextView
    android:text="Test 2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="@style/TexViewStyle"/>`
Praveen
  • 697
  • 6
  • 21