【问题标题】:How to replicate Inbox floating action button (with text for each sub button)?如何复制收件箱浮动操作按钮(每个子按钮都有文本)?
【发布时间】:2015-01-16 13:19:12
【问题描述】:
【问题讨论】:
标签:
java
android
view
android-custom-view
floating-action-button
【解决方案1】:
由于标签 FAB 功能(如在 Evernote 或 Inbox 应用程序中)已添加到这个很棒的 library 中,请随意使用它:
Gradle 依赖:
compile 'com.getbase:floatingactionbutton:1.3.0'
布局.xml:
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/multiple_actions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
fab:fab_addButtonColorNormal="@color/white"
fab:fab_addButtonColorPressed="@color/white_pressed"
fab:fab_addButtonPlusIconColor="@color/half_black"
fab:fab_labelStyle="@style/menu_labels_style"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp">
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/white"
fab:fab_title="Action A"
fab:fab_colorPressed="@color/white_pressed"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/white"
fab:fab_title="Action B"
fab:fab_colorPressed="@color/white_pressed"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
menu_labels_style.xml:
<style name="menu_labels_style">
<item name="android:background">@drawable/fab_label_background</item>
<item name="android:textColor">@color/white</item>
</style>
fab_label_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/black_semi_transparent"/>
<padding
android:left="16dp"
android:top="4dp"
android:right="16dp"
android:bottom="4dp"/>
<corners
android:radius="2dp"/>
</shape>
享受吧!
【解决方案2】:
FloatinActionsMenu 是ViewGroup 它可以接受任何视图。
创建布局,如:
<FloatingActionsMenu
android:layout_height="wrap_content"
android:layout_width="wrap_content"
>
<RelativeView
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/floating_description_1"/>
<FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
//....
</RelativeLayout>
<RelativeView
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/floating_description_2"/>
<FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
//....
</RelativeLayout>
</FloatingActionsMenu>
样式TextView随心所欲、背景、文字颜色等。
请注意,第一个FloatingActionButton 将被替换为具有最大宽度的子视图的大小。您应该将其移动到最大的子宽度 - 第一个浮动按钮宽度。
如果您还想将 TextView 添加到该 FloatingAction,请通过 id R.id.fab_expand_menu 或 .getChildAt(0) 获取它,以编程方式将其包装在 xml 中并使用 addView(0, wrapped) 设置它
如果我有时间修复它,我打算分叉。我将发布一个指向 fork 的链接。