i have set a floating action button background as translucent but when i set image resource it happen to be translucent too how can i remove translucent in an image resource in floating action button
xml codes.
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fabwallaper"
android:layout_marginLeft="25dp"
app:borderWidth="0dp"
android:layout_marginBottom="3dp"
android:elevation="6dp"
app:pressedTranslationZ="16dp"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|left|start"
android:backgroundTint="@color/colorAccent"
/>
java code.
actionButton=(FloatingActionButton) findViewById(R.id.fabwallaper);
actionButton.setAlpha(0.25f);
actionButton.setImageResource(R.drawable.ic_terrain_white);
You need to set image from XML file. Try this one android:src="@drawable/your_image_res"
and change android:backgroundTint="@color/colorPrimary"
to app:backgroundTint="@color/colorPrimary"
.
Look at that difference:
android:backgroundTint="@color/colorPrimary"
app:backgroundTint="@color/colorPrimary"
You're setting the button as translucent. Try using the alpha percentage with the backgroundTint color, so you'd set
android:backgroundTint="@color/colorWithAlphaLevel"
And your ImageResource would not be affected.
To set apha do a color, just add 1 byte to your original color, for example:
#000000
represents a full black, adding 1 more byte it would be #FF000000
For 25% alpha you would need #40000000
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.