Reputation: 21
I have used the following code to add ripple effect to my button, but the border around it has disappeared and the button has merged with the back ground. I want to add border around it to distinguish it.
This is the code of my button:
<Button
android:id="@+id/email_sign_in_button"
style="?android:textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:textColor="#ffffff"
android:text="@string/action_sign_in" />
This is the drawable for the button:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="1dp"
android:bottomRightRadius="1dp"
android:radius="0.1dp"
android:topLeftRadius="1dp"
android:topRightRadius="1dp" />
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="#E8E6E7" />
</shape>
Upvotes: 2
Views: 1687
Reputation: 720
You can actually have both by using background
and foreground
properties, like so:
android:background="@drawable/the_name_of_your_button_file"
android:foreground="?android:attr/selectableItemBackground"
Upvotes: 1
Reputation: 1013
android:background="?attr/selectableItemBackground"
is causing the button to take on the theme, and blend into the background as if transparent. You are not pointing to the drawable file for the button, which has the stroke element, which gives the border.
If you want a border, you must use the stroke element in your drawable by pointing to it with:
android:background="@drawable/the_name_of_your_button_file"
Upvotes: 0