在浮动操作按钮中删除透明的imageresource

时间:2019-02-23 12:44:32

标签: android

我将浮动操作按钮背景设置为半透明,但是当我设置图像资源时,它也恰好是半透明的,我该如何去除图像中的半透明 浮动操作按钮中的资源

xml代码。

    <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代码。

        actionButton=(FloatingActionButton) findViewById(R.id.fabwallaper);
    actionButton.setAlpha(0.25f);
    actionButton.setImageResource(R.drawable.ic_terrain_white);

2 个答案:

答案 0 :(得分:0)

您需要通过 XML 文件设置图片。试试这个android:src="@drawable/your_image_res",然后 将android:backgroundTint="@color/colorPrimary" 更改为 app:backgroundTint="@color/colorPrimary"

看看有什么区别:

android:backgroundTint =“ @ color / colorPrimary”

enter image description here

app:backgroundTint =“ @ color / colorPrimary”

enter image description here

答案 1 :(得分:0)

您正在将按钮设置为半透明。尝试将alpha百分比与backgroundTint颜色一起使用,以便进行设置

android:backgroundTint="@color/colorWithAlphaLevel"

您的ImageResource不会受到影响。

要设置apha颜色,只需将1个字节添加到您的原始颜色即可,例如:

#000000代表全黑,再加上1个字节即为#FF000000

对于25%的Alpha,您需要#40000000