Home > Mobile >  Why the button doesn't get all the attributes from xml
Why the button doesn't get all the attributes from xml

Time:05-03

I have created a xml file called round_button. It's a simple circular button with a gradient. Here is the simple code

    <?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
    xmlns:android="http://schemas.android.com/apk/res/android">
            <corners android:radius="3000dip" />
            <gradient android:type="linear" android:startColor="#8dbab3" android:endColor="#0DCAAC" />
</shape>

And that's the output:

Here is the code of the xml file of my main activity.

 <Button
    android:id="@ id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@ id/city"
    android:text="Search"
    android:background="@drawable/round_button"
   />

but the output is this one:

why it doen's have the gradient while the shape is correct?

CodePudding user response:

Go to themes.xml and change parent. parent=Theme.MaterialComponents.NoActionBar.Bridge

<style name="Theme.YourApp" parent="Theme.MaterialComponents.NoActionBar.Bridge">
        //yourcode
    </style>

CodePudding user response:

Everything in your code is okay just change Button to androidx.appcompat.widget.AppCompatButton like below and you will be able to achieve your desire result.

<androidx.appcompat.widget.AppCompatButton
  android:id="@ id/button"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentRight="true"
  android:layout_toRightOf="@ id/city"
  android:text="Search"
  android:background="@drawable/round_button"
/>
  • Related