简体   繁体   English

如何复制收件箱浮动操作按钮(每个子按钮有文本)?

[英]How to replicate Inbox floating action button (with text for each sub button)?

I was just wondering if anyone has any idea on how to replicate the floating action button view the new Inbox app has for android? 我只是想知道是否有人知道如何复制新的收件箱应用程序为Android的浮动操作按钮视图? I have the floating action buttons working (with sub buttons) working with a modified version of this library: https://github.com/futuresimple/android-floating-action-button/blob/master/README.md 我有浮动操作按钮工作(带子按钮)使用此库的修改版本: https//github.com/futuresimple/android-floating-action-button/blob/master/README.md

However I am having trouble trying to get the textview next to the button, like in the inbox app. 但是我在尝试获取按钮旁边的textview时遇到了麻烦,就像在收件箱应用程序中一样。

If someone could offer me a suggestion on how i would go about modifying the library to accommodate this, or any other way of achieving it, i would much appreciate it. 如果有人能给我一个关于如何修改图书馆以适应这个或任何其他实现方式的建议,我将非常感激。

Thanks for your time Corey 谢谢你的时间科里

Since Labels FAB feature (like in Evernote or Inbox apps) was added to this awesome library feel free to use it: 由于标签FAB功能(如在Evernote或Inbox应用程序中)被添加到这个很棒的库中,可以随意使用它:

Gradle dependency: Gradle依赖:

    compile 'com.getbase:floatingactionbutton:1.3.0'

Layout.xml: Layout.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: 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: 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>

Enjoy! 请享用!

FloatinActionsMenu is ViewGroup it can accept any view. FloatinActionsMenuViewGroup它可以接受任何视图。

Create layout like: 创建布局,如:

<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>

Style TextView as your heart desires, backgrounds, text color etc. 样式TextView作为您的心脏欲望,背景,文本颜色等。

Please note that first FloatingActionButton will be displaced to the size of child view that has largest width. 请注意,第一个FloatingActionButton将被移位到具有最大宽度的子视图的大小。 You should move it to largest child width - first floating button width. 您应该将其移动到最大子宽度 - 第一个浮动按钮宽度。

If you want to add TextView also to that FloatingAction, get it by id R.id.fab_expand_menu , or .getChildAt(0) , wrap it programatically as you would do it in xml and set it using addView(0, wrapped) 如果你想将TextView也添加到那个FloatingAction中,可以通过id R.id.fab_expand_menu.getChildAt(0)来获取它,像在xml中那样以编程方式包装它并使用addView(0, wrapped)设置它

I'm planning to fork, if by any chance I have time to fix it. 我打算分叉,如果有机会我有时间修理它。 I'll post a link to the fork. 我将发布一个指向fork的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM