I am trying to set gradient color in Button (in android studio whose version is Arctic Fox).
gradientbuttonmainactivity.xml I made this file in Drawable.
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#93501C"
android:endColor="#A67E7E"
android:type="linear"
android:angle="360"/>
<corners
android:radius="25dp"/>
</shape>
activity_main.xml
<Button
android:id="@ id/btnR"
android:layout_width="275dp"
android:layout_height="55dp"
android:layout_marginStart="55dp"
android:layout_marginTop="25dp"
android:background="@drawable/gradientbuttonmainactivity"
android:text="@string/register" />
but Button color is as it was, corners values applied but gradient values did'nt.
I searched it on google but didn't found any working solution.
In one stackoverflow answer, a writer said to change the colorPrimary (in theme.xml) with @null
. I done this , and gradient color applied, but on Run, the app failed to open in the smartphone, however, it launched successfully.
So, the question is clear, How do I make the button with gradient color ? Thank You.
CodePudding user response:
As an alternative, try using
androidx.appcompat.widget.AppCompatButton
instead of
Button
it might be a recent change with Button and Android's material design, I've noticed on older projects what you have implemented works with Button but on a more recent project, that background is not working