0

I am using Android Studio to display a circular button. Here is the code(activity_main.xml),

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hp.tmp.MainActivity">

<Button
    android:id="@+id/angry_btn"

    android:text="Click"
    android:textColor="#000000"
    android:textSize="15sp"

    android:layout_width="95dp"
    android:layout_height="95dp"
    android:background="@drawable/button"
    android:backgroundTint="#ed8181" />
</RelativeLayout>

button.xml in Drawable

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <corners
        android:radius="100dp"
        />
    <padding
        android:left="0dp"
        android:top="0dp"
        android:right="0dp"
        android:bottom="0dp"
        />
    <size
        android:width="100dp"
        android:height="100dp"
        />
</shape>

Here is the output (expected) on the emulator (Nexus 5 API 23) expected

Here is the output on the android device (HTC desire 616) with Android version 4.2.2 actual

I have set the minimum sdk for the project as 14. Would really appreciate help. Thank you for your valuable time.

snancy
  • 1
  • 1

1 Answers1

0

your problem is that android:backgroundTint="#ed8181" is API Level 21 and your HTC desire 616 has Api level 19.

Change your code the following way and it works.

Layout

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <Button
        android:id="@+id/angry_btn"

        android:text="Click"
        android:textColor="#000000"
        android:textSize="15sp"

        android:layout_width="95dp"
        android:layout_height="95dp"
        android:background="@drawable/button"
         />
</RelativeLayout>

Ressource File

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="#ed8181" />
    <corners android:radius="100dp" />
    <padding
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp" />
    <size
        android:width="100dp"
        android:height="100dp" />
</shape>