how to create a border around constraint layout along with an option for title

All above answers are focusing on creating new layouts. But you don’t suppose to do that. Just create a TextView below your constraint layout.

 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif"
        android:text="@string/time_range"
        android:textColor="@color/logoDark"
        android:textCursorDrawable="@drawable/cursor_style"

        // Below are very important to achieve title on border 
        android:paddingStart="2dp" 
        android:paddingEnd="2dp" 
        android:layout_marginStart="10dp" 
        android:background="@color/cnstrbkg" 
        app:layout_constraintBottom_toTopOf="@+id/cnstLyt" 
        app:layout_constraintStart_toStartOf="@+id/cnstLyt" 
        app:layout_constraintTop_toTopOf="@+id/cnstLyt" /> 

The positioning of textview is very very important thing. Change it to move text view at any position you want.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top