mr debug
mr debug

Reputation: 199

how to set border bottom of a view in android

I am trying to set bottom border of a TextView in Android by using layer-list drawable but the issue is that i am seeing corners a little bit upside from bottom but not a straight line under textview. I want it to be perfect straight line not curved around.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <!-- draw a 4 dp width border around the rectangle shape -->
            <stroke android:color="@color/colorPrimary" android:width="2dp"/>
        </shape>
    </item>
    <!--
        hide left, top and right side border using white color
        by padding 4 dp bottom side
    -->
    <item android:bottom="3dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white"/>
        </shape>
    </item>
</layer-list>




  <TextView
        android:gravity="center"
        android:text="@string/eat"
        android:textSize="12sp"
        android:background="@drawable/border_bottom_green_tab"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

the result I am getting

Upvotes: 0

Views: 1109

Answers (2)

V-rund Puro-hit
V-rund Puro-hit

Reputation: 5534

Just use solid instead of stroke in first item

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <!-- draw a 4 dp width border around the rectangle shape -->
        <solid android:color="@color/colorPrimary" />
    </shape>
</item>
<!--
    hide left, top and right side border using white color
    by padding 4 dp bottom side
-->
<item android:bottom="3dp">
    <shape android:shape="rectangle">
        <solid android:color="@android:color/white" />
    </shape>
</item>

Upvotes: 0

Faisal Naseer
Faisal Naseer

Reputation: 4248

this will work for you just change 3dp to 1dp for android:bottom

<?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:color="@color/colorPrimary" android:width="2dp"/>
        </shape>
    </item>

    <item android:bottom="1dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white"/>
        </shape>
    </item>
</layer-list>

Upvotes: 2

Related Questions