A
A
ArturPendragonOfficial2021-03-27 18:59:38
Kotlin
ArturPendragonOfficial, 2021-03-27 18:59:38

Why doesn't the button in xml change color?

My problem is this. I want my button to be black with a white stroke.
I made a separate xml file where I wrote everything.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="0dp"
    android:shape="ring"
    android:thicknessRatio="2"
    android:useLevel="false" >

    <solid android:color="@android:color/black" />

    <stroke
        android:width="5dp"
        android:color="@android:color/white" />
</shape>


Further I try to apply all this in floatingActionBar. The stroke works but the default color of the button remains green.

<LinearLayout
    android:id="@+id/fabWrapper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/button_background"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    android:padding="5dp">

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>


My guess is that something in the view hierarchy is preventing me from setting my color.
How can I fix this?

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.QuitSmoking" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
    </style>

    <style name="Theme.QuitSmoking.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="Theme.QuitSmoking.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="Theme.QuitSmoking.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
ArturPendragonOfficial, 2021-03-28
@ArturPendragonOfficial

I solved the problem. Removing all the themes created by the studio. They didn't let me set the color

D
Denis Zagaevsky, 2021-03-27
@zagayevskiy

So you set the background not to the button, but to the linear layout in which it lies for some reason. Set button.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question