Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlined MaterialButton doesn't show any border

I'm trying to build a layout with a bordered button as shown below (Expected behavior). From Material design documentation I read about Outlined Material Button that seemed to be perfect for my purpose. I defined the button in my layout, providing stroke width and stroke color but it isn't showing any border, what am I doing wrong?

<com.google.android.material.button.MaterialButton
            android:id="@+id/material_text_button"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:text="Change name"
            android:background="@android:color/transparent"
            android:textSize="12sp"
            app:layout_constraintBottom_toBottomOf="@+id/listTextView2"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/listTextView2"
            app:layout_constraintTop_toTopOf="@+id/listTextView2"
            app:strokeColor="@color/green"
            app:strokeWidth="10dp" />

Expected behavior:

enter image description here

Current behavior:

enter image description here

like image 480
Nicola Gallazzi Avatar asked Mar 27 '19 15:03

Nicola Gallazzi


1 Answers

Just add this attribute to your MaterialButton

android:theme="@style/Theme.MaterialComponents"

avoid to add it to your main theme.

example:

<com.google.android.material.button.MaterialButton
            android:id="@+id/material_text_button"
            style="@style/Widget.MaterialComponents.Button.OutlinedButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:theme="@style/Theme.MaterialComponents"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:text="Change name"
            android:background="@android:color/transparent"
            android:textSize="12sp"
            app:layout_constraintBottom_toBottomOf="@+id/listTextView2"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/listTextView2"
            app:layout_constraintTop_toTopOf="@+id/listTextView2"
            app:strokeColor="@color/green"
            app:strokeWidth="10dp" />
like image 131
appersiano Avatar answered Oct 27 '22 01:10

appersiano