Saturday, May 15, 2021

How to Add One Side Left Border in Android using XML

How to Add One Side Left Border in Android using XML

How to Add One Side Left Border in Android using XML

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="#fff"

    tools:context="com.android_examples.onesidebordertextview_android_examplescom.MainActivity">


    <TextView

        android:layout_width="fill_parent"

        android:layout_height="100dp"

        android:text="This is Sample TextView Text."

        android:background="@drawable/text_style"

        android:gravity="center"

        android:layout_centerHorizontal="true"

        android:layout_centerVertical="true"

        android:layout_margin="12dp"

        android:textSize="20dp"

        android:textColor="#000"

         />


</RelativeLayout>

text_style.xml

<?xml version="1.0" encoding="utf-8"?>


<layer-list xmlns:android="http://schemas.android.com/apk/res/android">


    <item>

        <shape android:shape="rectangle">

            <solid android:color="#F44336"/>

        </shape>

    </item>


    <item android:left="4dp">

        <shape android:shape="rectangle">

            <solid android:color="#FFEB3B"/>

        </shape>

    </item>


</layer-list>

No comments:

Post a Comment