skip to Main Content

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?

2

Answers


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

    <style name="Theme.YourApp" parent="Theme.MaterialComponents.NoActionBar.Bridge">
            //yourcode
        </style>
    
    Login or Signup to reply.
  2. 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"
    />
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search