【问题标题】:I can't hide Floating Action Button?我无法隐藏浮动操作按钮?
【发布时间】:2020-05-28 21:00:57
【问题描述】:

我试图通过单击按钮来隐藏我的 FAB,但它不起作用。?

我的 XML

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fabbb"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:layout_margin="@dimen/_10sdp"
    android:src="@drawable/ic_arrow_forward_black_24dp"
    android:tint="@color/md_white_1000" />

<Button
    android:id="@+id/show"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/_10sdp"
    android:text="HIDE" />

我的活动

show.setOnClickListener {
        fabbb.visibility == View.GONE
    }

【问题讨论】:

  • 使用fabbb.visibility = View.GONE

标签: android android-studio android-layout floating-action-button material-components-android


【解决方案1】:

使用方法hide

fab.hide();

【讨论】:

    【解决方案2】:

    你需要调用一个函数来隐藏和显示FAB

    隐藏fab.hide() 显示fab.show() 查看文档here

    【讨论】:

      【解决方案3】:

      您当前的代码什么都不做,而不是返回truefalse(很可能是true,因为您使用的是comparison 而不是equal-to)。

      你应该把代码写成

      show.setOnClickListener {
          fabbb.visibility = View.GONE
      }
      

      或者你甚至可以使用fabbb.hide(),如果你也需要动画,建议使用另一个答案。

      【讨论】:

        猜你喜欢
        • 2016-07-27
        • 1970-01-01
        • 1970-01-01
        • 2015-12-13
        • 1970-01-01
        • 2016-06-24
        • 2016-11-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多