How do I add borders up and down in Android view?

Asked 2 years ago, Updated 2 years ago, 156 views

I added attributes to android:drawableTop and android:drawablebottom like the code below to put a black border line on the text view, but the view itself turned black.

<TextView
    android:background="@android:color/green"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:drawableTop="@android:color/black"
    android:drawableBottom="@android:color/black"
    android:text="la la la" />

Can't we just put the border on the top and bottom?

android border android-view android-textview

2022-09-22 13:30

1 Answers

In Android 2.2, in text view

<TextView
android:text="My text with lines above and below"
android:background="@drawable/textlines"/>

Do it

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
      <shape android:shape="rectangle">
      <stroke android:width="1dp" android:color="#FF000000" />
        <solid android:color="#FFDDDDDD" />
        </shape>
   </item>

   <item android:top="1dp" android:bottom="1dp"> 
      <shape android:shape="rectangle">
      <stroke android:width="1dp" android:color="#FFDDDDDD" />
        <solid android:color="#00000000" />
        </shape>
   </item>
</layer-list>

Please do it like this.


2022-09-22 13:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.