Search code examples
androidbuttondivider

Adding a horizontal divider at top of button


I am trying to add a horizontal divider on the top of the button with transparent background but the divider is not visible, while the background has been set successfully.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="fill_parent">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/layout"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.example.salimshivani.student.MainActivity"
        tools:showIn="@layout/activity_main">

        <EditText
            android:id="@+id/editTextUser"
            android:layout_width="320dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="250dp"
            android:hint="@string/userName"
            android:inputType="textEmailAddress" />

        <EditText
            android:id="@+id/editTextPassword"
            android:layout_width="320dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/editTextUser"
            android:layout_centerHorizontal="true"
            android:hint="@string/password"
            android:inputType="textPassword" />

        <Button
            android:id="@+id/buttonSignIn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/editTextPassword"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="110dp"
            android:text="@string/buttonSignIn" />

        <android.widget.Button
            android:id="@+id/buttonSignUp"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="?android:attr/selectableItemBackground"
            android:layout_below="@id/buttonSignIn"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="69dp"
            android:shape="rectangle"
            android:layout_gravity="bottom|end|fill_horizontal"
            android:text="@string/buttonSignUp"
            android:textAlignment="center" />

    </RelativeLayout>

</ScrollView>

</RelativeLayout>

Thanks in advance for any help


Solution

  • The simple way is to define an empty view, like

    <View android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#333"
        android:layout_above="@+id/buttonSignUp" />
    

    Put it after or before your Button tag in xml file.

    I hope it works.