简体   繁体   English

是否可以在浮动操作按钮android顶部设置图标

[英]Is it possible to set an icon on top of a Floating action button android

I want to add the items to the cart. 我要将物品添加到购物车中。 The cart will be Floating action button and item count I want to show on top of it. 购物车上将显示“浮动操作”按钮和要显示在其上方的物品计数。 Please help me with this. 请帮我解决一下这个。

I want something like this 我想要这样的东西

在此处输入图片说明

button tint to keep background color in your case it will be orange src will be the above image which u have in white a dish container you can use a frame layout and make another button and align than to top right 按钮颜色,以保持背景颜色为您的情况,它将是橙色src将是您在白色的白色容器中的上面的图像,您可以使用框架布局并制作另一个按钮,然后比右上角对齐

<android.support.design.widget.FloatingActionButton
        android:id="@+id/add_new"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_add_white"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:backgroundTint="@color/red"
        android:layout_margin="@dimen/margin_10"/>

In your coordinator layout please add these and you'll have the desired effect 在您的协调器布局中,请添加这些,您将获得理想的效果

  <android.support.design.widget.FloatingActionButton android:id="@+id/panic_fab" android:layout_width="60dp" android:layout_height="60dp" android:layout_gravity="bottom|right" android:layout_marginBottom="15dp" android:layout_marginRight="15dp" android:background="@drawable/clip_gradient" android:elevation="12dp" android:src="@drawable/ic_error_outline_black_24dp" app:elevation="6dp" app:pressedTranslationZ="12dp" /> <android.support.design.widget.FloatingActionButton android:id="@+id/panic_fab1" android:layout_width="20dp" android:layout_height="20dp" android:layout_gravity="bottom|right" android:layout_marginBottom="15dp" android:layout_marginRight="15dp" android:background="#fff" android:elevation="12dp" android:src="@drawable/notification" app:elevation="8dp" app:pressedTranslationZ="12dp" /> 

在此处输入图片说明

i have tested this hope this will work for you. 我已经测试过这一希望,它将对您有用。 Do some changes acording to ua requirements 根据UA要求进行一些更改

 <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/add_new"
        android:layout_width="60dp"
        android:layout_height="@dimen/margin_60"
        android:src="@drawable/ic_add_white"
        android:padding="@dimen/margin_20"
        android:backgroundTint="@color/red"
        android:layout_margin="@dimen/margin_10"/>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/add_nw"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="right"
            android:layout_marginTop="@dimen/margin_5"
            android:backgroundTint="@color/blue"
            android:src="@drawable/ic_add_white" />
    </FrameLayout>

You can use constraintlayout. 您可以使用constraintlayout。 It will be easier i this case 在这种情况下会更容易

在此处输入图片说明

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

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