【问题标题】:Floating button Background Color浮动按钮背景颜色
【发布时间】:2019-01-31 05:41:33
【问题描述】:

我在更改 FAB 背景颜色时遇到问题,FAB 后面似乎有另一个背景

这是我的代码

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|end">

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_margin="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:backgroundTint="@color/colorPrimary"
        android:src="@android:color/transparent" />

    <TextView
        android:id="@+id/text_vote"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@android:string/ok"
        android:elevation="16dp"
        android:includeFontPadding="false"
        android:textColor="@android:color/white"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</FrameLayout>

我想去掉它后面的紫色/粉红色。现在唯一可行的解​​决方案是更改我应用上的 colorAccent,但它会影响其他 UI 元素

【问题讨论】:

  • 从浮动按钮中移除背景色调
  • 或者使用这个android:backgroundTint="@android:color/transparent"
  • android:backgroundTint="@color/colorPrimary" 设置它null 或transparent

标签: java android floating-action-button


【解决方案1】:

试试这个代码: 我在 FloatingActionButton 中添加了这一行

app:backgroundTint="#000"

改变 FloatingActionButton 背景

代码

 <android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:backgroundTint="#000"
    app:srcCompat="@android:drawable/ic_dialog_email" />

希望对你有用

【讨论】:

    【解决方案2】:

    你可以像下面这样android:backgroundTint="@color/pink"

    【讨论】:

      【解决方案3】:

      只需添加:

      app:borderWidth="0dp"
      

      【讨论】:

        猜你喜欢
        • 2019-10-04
        • 2019-05-16
        • 2013-06-24
        • 2012-04-02
        • 1970-01-01
        • 2021-04-19
        • 1970-01-01
        • 2020-08-19
        • 2013-08-06
        相关资源
        最近更新 更多