【问题标题】:Floating action button is not showing in api 24api 24 中未显示浮动操作按钮
【发布时间】:2020-12-18 15:25:32
【问题描述】:

以下代码中的 FAB 显示在 api 29 手机中,但未显示在 api 24 手机中。如何解决这个问题? 我使用材料设计库和导航组件。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".ui.HomeFragment">

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/btn_add"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:clickable="true"
    app:tint="@android:color/white"
    android:src="@drawable/ic_add"
    />
</RelativeLayout>

【问题讨论】:

    标签: android material-design floating-action-button


    【解决方案1】:

    试试这个代码:

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/btn_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:clickable="true"
        app:tint="@android:color/white"
        app:srcCompat="@drawable/ic_add"
        />
    

    【讨论】:

    • 也许你可以在 logcat 中搜索 Floating Action Button 的错误,如果你愿意,可以发布它们。可能会有所帮助:)
    • 说真的,我不知道如何重新创建它。您的代码,当我将其导入新项目时,工作正常。
    猜你喜欢
    • 2016-11-09
    • 1970-01-01
    • 2022-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多