Изложенное MaterialButton не показывает границы - PullRequest
0 голосов
/ 27 марта 2019

Я пытаюсь создать макет с помощью кнопки с рамкой, как показано ниже (ожидаемое поведение). Из документации по дизайну материалов я прочитал о кнопке Outlined Material, которая, казалось, идеально подходила для моих целей. Я определил кнопку в своем макете, предоставляя ширину обводки и цвет обводки, но она не показывает границ, что я делаю неправильно?

<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" />

Ожидаемое поведение:

enter image description here

Текущее поведение:

enter image description here

Ответы [ 2 ]

1 голос
/ 29 марта 2019

Просто добавьте этот атрибут к вашему MaterialButton

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

не добавляйте его в основную тему.

пример:

<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" />
1 голос
/ 27 марта 2019

попробуйте удалить прозрачный фон и стиль из вашего xml.а также убедитесь, что изменили стиль на MaterialComponents.

  <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> 

 <com.google.android.material.button.MaterialButton
        android:id="@+id/btn_login"
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:layout_marginStart="20dp"
        android:layout_marginTop="20dp"
        android:textSize="16sp"
        android:layout_marginEnd="20dp"
        android:text="works"
        android:textAllCaps="false"
        android:textColor="@color/white"
        app:strokeColor="@color/white"
        app:strokeWidth="2dp" />
...