按钮的颜色不会改变机器人工作室

0

的问题

我有一个按钮,那有两个国家在其它有一个不同的颜色,但是的颜色不会改变,因为这颜色的按钮是自动设定的主题。 我如何可以避免的颜色主题有设置?

按钮码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity"
    android:background="@color/purple_200">

    <LinearLayout
        android:id="@+id/startLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:padding="10dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/add_note"
            android:layout_width="0dp"
            android:layout_height="65dp"
            android:layout_weight="1"
            android:textSize="23sp"
            android:background="@drawable/button_states"
            android:text="@string/add_button" />
    </LinearLayout>
</RelativeLayout>

国家代码:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="@color/white"/>
            <stroke android:color="@color/purple_200" android:width="1dp"/>
        </shape>
    </item>
    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="@color/purple_200"/>
            <stroke android:color="@color/purple_500" android:width="1dp"/>
        </shape>
    </item>
</selector>

主题代码:

<resources>
    <style name="Theme.NotifyMe" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <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>
    </style>
</resources>
android android-studio button java
2021-11-24 06:32:06
2

最好的答案

0

任您使用的按钮从androidx库 androidx.appcompat.部件。AppCompatButton 或设置的财产按钮 backgroundTintMode 在xml到可绘.

理想的情况是你想要使用的背景财产,使其最好的,你用这个

 <androidx.appcompat.widget.AppCompatButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="64dp"
        android:text="Button"
        android:background="@drawable/button_states"
        app:layout_constraintStart_toStartOf="parent"
        tools:layout_editor_absoluteY="106dp" />
2021-11-24 09:18:05
-1
<RelativeLayout 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=".MainActivity"
android:background="@color/purple_200">

<LinearLayout
    android:id="@+id/startLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:padding="10dp"
    android:orientation="horizontal">

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/add_note"
        android:layout_width="0dp"
        android:layout_height="65dp"
        android:layout_weight="1"
        android:textSize="23sp"
        android:background="@drawable/button_states"
        android:text="Add Button" />
</LinearLayout>
</RelativeLayout>
2021-11-24 06:55:32

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................