android - 有什么方法可以通过 xml 隐藏 FAB( float 操作按钮)?

标签 android floating-action-button

有什么方法可以在不编辑 Java 文件的情况下通过 xml 文件隐藏/禁用 Android 中的 float 操作按钮?只想在应用程序中隐藏共享按钮,我尝试编辑相关的 xml 文件。试图设置不可见、消失等,但这些都不起作用。按钮还在。至少将按钮的大小减小到几乎看不见?我认为我们不能将 fab:fab_size="normal" 更改为其他值。所以那也行不通。那有什么办法吗??

最佳答案

Discussed已经在这个问题上, 主要原因是

If you set a set a FloatingActionButton to be anchored, you lose control of the visibility.

所以你必须先从 FloatingActionButton 中移除 layout_anchor 属性。

此时您必须在某处使用 java。不能只用 XML 来做 给出的技巧是

To wrap your FAB in a coordinator layout that is not the root of your entire layout, but as a sort of overlay to everything. From there you can manage the visibility of the coordinator layout initially so it's invisible, then make it visible when you call fab.show().

关于android - 有什么方法可以通过 xml 隐藏 FAB( float 操作按钮)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36540951/

相关文章:

java - 获取适用于 Android 和 PC 的 Preferences API

android - 从url下载文件到cordova app错误

java - 如何让 float 操作按钮消耗点击事件?

android - FloatingActionButton、layout_anchor 和 layout_gravity

Android FAB拖放

android - 可以在 RelativeLayout 内部的表面上使用 setFixedSize 吗?

android - 简单的 TextView.setText 导致 40% 的 CPU 使用率

java - 在相机预览中显示图像?

android - 右下角的 float 操作按钮

android - 在键盘上方设置 FAB( float 操作按钮)