简体   繁体   中英

Java android FloatingActionButton set image and color

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

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);

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);

I Hope this will work for you.

Instead of this

android:tint="@color/green"

Use

android:backgroundTint="#008000"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM