0

Мне нужно чтобы у button был определенный стиль, я создал для этого отдельный xml файл, но почему-то button свой стиль не меняет. Я попробовал разный код, но результат один и тот же, я не знаю что делать уже

Вот код фрагмента

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".StartFragment"
    android:layout_gravity="center"
    android:layout_centerVertical="true">

 

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="161dp"
        android:background="@drawable/button_style"
        android:layout_marginTop="38dp"
        android:text="Button"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword" />

</androidx.constraintlayout.widget.ConstraintLayout>

Вот код стиля для button

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#3DE3E3" />

    <stroke
        android:width="10dp"
        android:color="#4C190B" />

</shape>

1 ответ 1

0

Вероятно у вас material design тема, в ней некоторые view в xml (<Button /> <TextView/> и другие) заменяются на Material версии, которые игнорят android:background атрибут.

У MaterialButton есть множество своих атрибутов для настройки стиля

<solid android:color="#3DE3E3" /> можно заменить на android:backgroundTint="#3DE3E3"

<stroke
        android:width="10dp"
        android:color="#4C190B" />

на

app:strokeWidth="10dp"
app:strokeColor="#4C190B"
<com.google.android.material.button.MaterialButton
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="161dp"
        android:layout_marginTop="38dp"
        android:text="Button"

        android:backgroundTint="#3DE3E3"
        app:strokeWidth="10dp"
        app:strokeColor="#4C190B"

        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword" />

Либо можно заменить тему или использовать <androidx.appcompat.widget.AppCompatButton/>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.