Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android按钮背景采用原色_Android_Xml_Button_Android Button_Material Components Android - Fatal编程技术网

Android按钮背景采用原色

Android按钮背景采用原色,android,xml,button,android-button,material-components-android,Android,Xml,Button,Android Button,Material Components Android,我有这个问题,我不知道它从哪里来,我已经创建了这个按钮与自定义背景,但背景色谈论的主要颜色,不能改变它,除非改变主要颜色 <Button android:id="@+id/btn_teacher" style="@style/normalText" android:layout_width="match_parent" android:layout_height="wrap_content

我有这个问题,我不知道它从哪里来,我已经创建了这个按钮与自定义背景,但背景色谈论的主要颜色,不能改变它,除非改变主要颜色

<Button
    android:id="@+id/btn_teacher"
    style="@style/normalText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/_16sdp"
    android:background="@drawable/btn_rounded_stroke"
    android:text="@string/txt_teacher" />

    <resources>
        <color name="colorPrimary">#008577</color>
        <color name="colorPrimaryDark">#00574B</color>
        <color name="colorAccent">#D81B60</color>
        <color name="bg_color">#FFD7A4</color>        
    </resources>
如何覆盖此颜色? 试试这个

您的按钮:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#FFFFFF"
    android:layout_margin="5dp"
    android:background="@drawable/round_btn"
    android:padding="20dp"
    android:text="My Text" />

这是您的圆形\u btn可绘图:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#008577" />
    <corners android:radius="20dp" />
</shape>

因为您使用的是
主题。MaterialComponents.
您的
按钮将替换为
MaterialButton

目前,
背景色
仍然是默认的材质按钮
样式。 这意味着,如果您使用的是自定义的
android:background
,则必须确保将
backgroundTint
置空,以避免自定义背景不会使用主题中定义的
attr/colorPrimary
着色

您必须添加app:backgroundTint=“@null”

  <Button
    app:backgroundTint="@null"
    android:background="@drawable/.."

在您的渐变中,只需更换这一行即可

implementation "com.google.android.material:material:1.3.0-alpha02"
用这个

 implementation 'com.google.android.material:material:1.2.1'

使用材质主题时,按钮视图将映射到MaterialButton。 在这种情况下,还有一种方法可以设置按钮背景

    <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar"
...
        <item name="materialButtonStyle">@style/ColoredButton</item>
    </style>

    <style name="ColoredButton" parent="Widget.MaterialComponents.Button.TextButton">
        <item name="backgroundTint">@color/customButtonColor</item>
    </style>

只需转到themes.xml文件并将样式名称更改为:

style name="Theme.AnimatedLogin" 
parent="Theme.AppCompat.Light.NoActionBar"
在轻主题模式下,并执行以下操作:

style name="Theme.AnimatedLogin"
parent="Theme.AppCompat.DayNight.NoActionBar"

在theme.xml中的黑暗主题模式下(夜间)文件,然后您可以自定义按钮并更改其颜色。

Post
@drwable/btn\u round\u stroke
xmli编辑了Post这里是我的可绘制类,但没有任何更改:---------------------------------------------------------------尝试过它不工作,它会变成蓝色不是我的习惯background@Fath.Saifpost ALL style=“@style/NORMETEXT”衷心感谢您。。。。❤
    <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar"
...
        <item name="materialButtonStyle">@style/ColoredButton</item>
    </style>

    <style name="ColoredButton" parent="Widget.MaterialComponents.Button.TextButton">
        <item name="backgroundTint">@color/customButtonColor</item>
    </style>
style name="Theme.AnimatedLogin" 
parent="Theme.AppCompat.Light.NoActionBar"
style name="Theme.AnimatedLogin"
parent="Theme.AppCompat.DayNight.NoActionBar"