Search code examples
androiduser-interfacedrawableandroiddesignsupport

Android Button drawable doesnt show


I want to have a circular button. It show's on the designer as expected but the button itself doesn't show on the actual device when running, nor when i click the position of the button it does absolutely nothing.

Why isn't the button showing?

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
 xmlns: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="#000">




<android.support.v7.widget.AppCompatButton
    android:id="@+id/security_calling_disarm"
    android:layout_width="wrap_content"
    android:layout_height="82dp"
    android:layout_marginBottom="91dp"
    android:layout_marginStart="56dp"
    android:background="@drawable/security_calling_disarm"
    android:visibility="visible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

Drawable file

<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
        <solid android:color="#00FF00"/>
    </shape>

Solution

  • Since you're setting the layout_width to wrap_content the shape is missing a width to be drawn.

    Try changing it to something like this:

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/security_calling_disarm"
        android:layout_width="0dp"
        android:layout_height="82dp"
        android:layout_marginBottom="91dp"
        android:layout_marginStart="56dp"
        android:background="@drawable/security_calling_disarm"
        android:visibility="visible"
        app:layout_constraintDimensionRatio="1:1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
    

    This way app:layout_constraintDimensionRatio="1:1" and android:layout_width="0dp" will make sure the width matches the height.