0

I want to do this : FloatingActionButton I want to set an Image and change color to : GREEN . I try do this :

 <com.smok.maps.fab.FloatingActionButton
            android:id="@+id/list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ikona2"
            android:tint="@color/green"
            app:layout_anchor="@id/mapview"
            app:layout_anchorGravity="bottom|left|end" />

But this floatingActionButton still is red

kpokrywja
  • 199
  • 1
  • 11

3 Answers3

1

Pragmatically you can change background color:

aBu.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.white))); 

in xml you can use :

app:backgroundTint="@color/red"

Or Set a Button using below code:

aBu.setImageResource(R.drawable.ic_image_name);
Ali
  • 3,346
  • 4
  • 21
  • 56
0

Try app:backgroundTint .FloatingActionButton is from support library so you must use app namespace. android namespace can lead to crash or improper working

android is usually used for attribute coming from Android SDK itself.

app is often used if you are using the support library.

<com.smok.maps.fab.FloatingActionButton
            android:id="@+id/list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ikona2"
            app:backgroundTint="@color/green"
            app:layout_anchor="@id/mapview"
            app:layout_anchorGravity="bottom|left|end" />

For setting Image try:

floatingActionButoon.setImageResource(R.drawable.ic_image_name);
Tomin B Azhakathu
  • 2,656
  • 1
  • 19
  • 28
-1

I Hope this will work for you.

Instead of this

android:tint="@color/green"

Use

android:backgroundTint="#008000"
GParekar
  • 1,209
  • 1
  • 8
  • 15