Search code examples
androidxmllayouttextdivider

how to put divider line between elements with text in the middle android?


i'm trying to design my android application so i need to create a separator line with text in the middle. i used this code XML to create the separator line:

   <View
    style="?android:attr/listSeparatorTextViewStyle"
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:layout_below="@+id/login_button"
    android:layout_marginTop="20dp"
    android:background="@android:color/white"
/>

but i didn't figure out how to put the text in the middle.

like this : ------- Text ------- but a coherent line


Solution

  • <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:text="-----------------------------"
        android:textColor="#ffff00" />
    
    <TextView
        android:id="@+id/but_book_now"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:background="@android:color/transparent"
        android:text="This is button"
        android:textColor="#ffff00" />
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:text="-----------------------------"
        android:textColor="#ffff00" />
    

    enter image description here