简体   繁体   English

如何使用单个可绘制文件更改按钮的颜色和半径?

[英]How to change the color and radius of button with single drawable file?

I want to change the Color and Radius of my button with single drawable file.我想用单个可绘制文件更改按钮的颜色和半径。 In the Drawable file I select the color and radius for my button.But when I call it in my MainActivity.XML it is only changing the radius of Button not the color of my Button Please Help.在 Drawable 文件中,我 select 是我的按钮的颜色和半径。但是当我在 MainActivity.XML 中调用它时,它只是改变了按钮的半径而不是我的按钮的颜色请帮助。

    <?xml version="1.0" encoding="utf-8"?>
<shape  android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="50dp"/>
    <solid android:color="@color/red"/>
    <Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="LOGIN"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:background="@drawable/button" />

You should use ImageButton instead of Button.您应该使用 ImageButton 而不是 Button。 https://developer.android.com/reference/android/widget/ImageButton https://developer.android.com/reference/android/widget/ImageButton

Change your Application Theme from MaterialComponents to AppCompat for example make it Theme.AppCompat.Light.NoActionBar将您的应用程序主题从MaterialComponents更改为AppCompat ,例如将其Theme.AppCompat.Light.NoActionBar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM