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:
Current behavior:
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With