【问题标题】:FAB background tint does not change in fragment but changes in activity?FAB 背景色调在片段中没有变化,但在活动中发生变化?
【发布时间】:2020-01-21 10:48:23
【问题描述】:

我以前在我的活动中使用过这个工厂,它工作正常,但现在我已经将我的代码从活动转移到了片段。现在我的布局中有 3 个 Fab,我无法更改背景颜色或其中任何一个。这是我的代码。我做错了什么还是出了什么问题?任何帮助将不胜感激?

附:我的工厂按钮的颜色是默认的 Aqua 颜色,甚至不是我的应用强调色,我可以在布局编辑器中看到反映的变化,但在我的设备上看不到!!

 <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab_change_map_type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:backgroundTint="@color/color_accent"
        android:onClick="@{(v) -> viewModel.onClick(v)}"
        android:src="@drawable/ic_change_map_display_type"
        android:visibility="@{viewModel.routeInfoViewModel.routeInfoViewEnabledLive ? View.GONE : View.VISIBLE}"
        app:borderWidth="0dp"
        app:fabSize="mini"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/card_gps_error"
        app:rippleColor="@color/color_accent" />

【问题讨论】:

    标签: android user-interface floating-action-button


    【解决方案1】:

    您应该为FloatingActionButtons 的backgroundTint 属性使用app: 命名空间。 Material Components reference

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab_change_map_type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ...
        app:backgroundTint="@color/color_accent"
        ...
         />
    

    【讨论】:

    • 但是你知道为什么这个 android:backgroundTint 在活动和片段中工作我必须使用材料组件参考吗?
    猜你喜欢
    • 2018-10-15
    • 2014-07-07
    • 1970-01-01
    • 2021-05-15
    • 1970-01-01
    • 2011-09-19
    • 2017-12-10
    • 2011-01-25
    • 1970-01-01
    相关资源
    最近更新 更多