简体   繁体   中英

How to put a label over the border of the TextView

Is there a way to position a label over the TextView border? (outlined border)

picture you attached is outlined textfield..

check this

But if you want to customize the same as picture then in relative layout add 2 textviews and positioned them both. like this

      <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/border"
                android:text="my text"
                android:textColor="@color/white"
                android:padding="@dimen/_20sdp"
                android:layout_margin="@dimen/_8sdp"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="my text"
                android:paddingEnd="@dimen/_5sdp"
                android:paddingStart="@dimen/_5sdp"
                android:textColor="@color/white"
                android:layout_marginLeft="@dimen/_25sdp"
                android:background="@color/black"
                />
        </RelativeLayout>

border.xml

<?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android">
 <stroke android:width="1dp" android:color="@color/white"/>
<corners android:radius="@dimen/_5sdp"/>
 </shape>

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM