【问题标题】:Android Floating Action Button Semi Transparent Background ColorAndroid 浮动操作按钮半透明背景色
【发布时间】:2016-09-26 17:19:24
【问题描述】:

我想使用具有半透明背景颜色的 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"/>

而且没有任何可绘制对象。

【问题讨论】:

  • 尝试在您的color.xml 中创建此颜色并使用app:backgroundTint="@color/yourcolor"
  • 定义你的颜色在您的项目中设置主题样式
  • @BOUTERBIATOualid 没有区别。
  • @MohammedSameerAhmad 不工作。
  • 尝试删除你的背景drawable,看看会发生什么

标签: android xml android-support-library floating-action-button


【解决方案1】:

除非需要高程,否则可以通过将“内圈”设置为0来去除:

app:elevation="0dp"

正如@David 在 cmets 中所说,如果 0 不起作用,您可能想尝试 1dp。

【讨论】:

  • 我有同样的问题,但只有app:elevation="1dp" 有帮助。 0 完全隐藏 FAB
  • 我猜这取决于不同的主题、API/SDK 等等?
【解决方案2】:

设置高度和pressedTranslationZ 零以移除效果

<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"/>

【讨论】:

    【解决方案3】:

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

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

    compile 'com.getbase:floatingactionbutton:1.10.1'
    

    到你的依赖,

    然后添加:

    <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"
                />
    

    到您的 XML 文件中。

    有效?

    【讨论】:

      【解决方案4】:

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

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

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

      而且外观现在是一致的。

      【讨论】:

      • 它有效,但这也使图标透明...:-/
      猜你喜欢
      • 2014-02-13
      • 2015-03-15
      • 2013-03-22
      • 1970-01-01
      • 1970-01-01
      • 2011-11-15
      • 2017-03-27
      • 2011-09-15
      • 1970-01-01
      相关资源
      最近更新 更多