Skip to content Skip to sidebar Skip to footer

Having An Issue Coloring Custome Xml Button

I'm having an issue coloring a custom button. For some reason, it seems like no matter what coloring change I want to apply (text or background) the button remains the same. I noti

Solution 1:

If you are using material components (which is probably the case if this is a relatively new project) then you style the Button in another way:

<androidx.constraintlayout.widget.ConstraintLayoutxmlns: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"android:background="@color/white"tools:context=".FirstFragment"><Buttonandroid:id="@+id/button"style="@style/Widget.MaterialComponents.Button"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="32dp"android:text="I am a Button!"android:textColor="@color/white"app:backgroundTint="#FF0000"app:cornerRadius="50dp"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

Things to notice are:

  • style="@style/Widget.MaterialComponents.Button"
  • android:textColor="@color/white"
  • app:backgroundTint="#FF0000" (would be @color/redAdobeXD in your case)
  • app:cornerRadius="50dp"

There is no need for an extra xml and setting that on the button etc. (only in more custom cases).

You can read more about available options on the ContainedButtonhere

Post a Comment for "Having An Issue Coloring Custome Xml Button"