javaandroidandroid-studioandroid-widgetandroid-button

Guidance in Android studio's Button widget


I am using Button and setting it's background as drawable image (Button not content any leading text, it's blank). I needed clickable image.

now the color of that png is black originally but some how in application it is purple.

how can i set it's color to black or any other?

setting button's backgroundTint property. result : doesn't change anything.

        <Button
            android:id="@+id/btn_open_money"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="end"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/dollar"
            android:contentDescription="Open money converter"
            android:visibility="visible" />

        <Button
            android:id="@+id/btn_open_calculator"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="end"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/calculator"
            android:visibility="gone" />

black color image (png)

purple color image


Solution

  • you can use style and add icon properties to the button

        <Button
            android:id="@+id/btn_open_money"
            style="@style/Widget.AppCompat.Button.Borderless"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="end"
            android:contentDescription="Open money converter"
            app:icon="@drawable/baseline_share_24"
            app:iconGravity="textStart"
            app:iconSize="40dp"
            app:iconTint="@color/black" />
    

    hope it works for you