Android浮动行动按钮半透明背景颜色

时间:2023-01-17 14:07:07

I want to use FAB with semi transparent background color. But I am getting a FAB with two different colors. What's the problem?

我想使用半透明背景颜色的FAB。但我得到了两种不同颜色的FAB。有什么问题?

<android.support.design.widget.FloatingActionButton
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|left"
    android:fadingEdgeLength="5dp"
    app:borderWidth="0dp"
    app:elevation="4dp"
    app:backgroundTint="#99f03456"
    app:fabSize="normal"/>

Android浮动行动按钮半透明背景颜色

And without any drawable.

并且没有任何可绘制的。

Android浮动行动按钮半透明背景颜色

4 个解决方案

#1


5  

Got the same issue here. I tried to set alpha transparency in xml using backgroundTint but it didn't work and resulted in the same appearance as in your screenshots (two circles).

这里有同样的问题。我尝试使用backgroundTint在xml中设置alpha透明度,但它不起作用,导致与屏幕截图(两个圆圈)相同的外观。

So I set it in code like this :

所以我在这样的代码中设置它:

floatingButton = (FloatingActionButton) findViewById(R.id.fab);
floatingButton.setAlpha(0.25f);

And the look is now consistent.

现在看起来一致。

#2


5  

Unless the elevation is necessary, you can remove the "inner circle" by setting it to 0:

除非需要提升,否则可以通过将其设置为0来删除“内圈”:

app:elevation="0dp"

#3


3  

Set elevation and pressedTranslationZ zero to remove the effects

设置高程并按下TransTransZ零以删除效果

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="onClickMyLocation"
    app:backgroundTint="@color/transparentColor"
    app:srcCompat="@drawable/ic_my_location"
    app:elevation="0dp"
    app:pressedTranslationZ="0dp"/>

#4


1  

I was able to solve the problem using Jerzy Chalupski floating action button: https://github.com/futuresimple/android-floating-action-button

我能够使用Jerzy Chalupski浮动操作按钮解决问题:https://github.com/futuresimple/android-floating-action-button

To use in your project add:

要在项目中使用,请添加:

compile 'com.getbase:floatingactionbutton:1.10.1'

to your dependencies,

对你的依赖,

and then add:

然后添加:

<com.getbase.floatingactionbutton.FloatingActionButton
            android:id="@+id/my_fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:layout_marginRight="8dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:onClick="myMethod"
            fab:fab_icon="@drawable/my_icon"
            fab:fab_colorNormal="@color/my_transparent_color"
            fab:fab_colorPressed="@color/white"
            />

into your XML file.

进入你的XML文件。

It works ????

它有效????

#1


5  

Got the same issue here. I tried to set alpha transparency in xml using backgroundTint but it didn't work and resulted in the same appearance as in your screenshots (two circles).

这里有同样的问题。我尝试使用backgroundTint在xml中设置alpha透明度,但它不起作用,导致与屏幕截图(两个圆圈)相同的外观。

So I set it in code like this :

所以我在这样的代码中设置它:

floatingButton = (FloatingActionButton) findViewById(R.id.fab);
floatingButton.setAlpha(0.25f);

And the look is now consistent.

现在看起来一致。

#2


5  

Unless the elevation is necessary, you can remove the "inner circle" by setting it to 0:

除非需要提升,否则可以通过将其设置为0来删除“内圈”:

app:elevation="0dp"

#3


3  

Set elevation and pressedTranslationZ zero to remove the effects

设置高程并按下TransTransZ零以删除效果

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="onClickMyLocation"
    app:backgroundTint="@color/transparentColor"
    app:srcCompat="@drawable/ic_my_location"
    app:elevation="0dp"
    app:pressedTranslationZ="0dp"/>

#4


1  

I was able to solve the problem using Jerzy Chalupski floating action button: https://github.com/futuresimple/android-floating-action-button

我能够使用Jerzy Chalupski浮动操作按钮解决问题:https://github.com/futuresimple/android-floating-action-button

To use in your project add:

要在项目中使用,请添加:

compile 'com.getbase:floatingactionbutton:1.10.1'

to your dependencies,

对你的依赖,

and then add:

然后添加:

<com.getbase.floatingactionbutton.FloatingActionButton
            android:id="@+id/my_fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:layout_marginRight="8dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:onClick="myMethod"
            fab:fab_icon="@drawable/my_icon"
            fab:fab_colorNormal="@color/my_transparent_color"
            fab:fab_colorPressed="@color/white"
            />

into your XML file.

进入你的XML文件。

It works ????

它有效????