如何在扩展浮动操作按钮上实现菜单显示并单击android [英] How to implement Menu display on Extended Floating Action Button click android

查看:506
本文介绍了如何在扩展浮动操作按钮上实现菜单显示并单击android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要实现在材料网站上所提到的格式扩展FAB按钮( https://开头kstatic.googleusercontent.com/files/8f9b57829c943c97be7c4b2485cf678f041dfe7c7ef523cfb2e97f1aeee21431f83d98cc07befeeed904fabb258298e3a7ac95f9da5d3da7a4adcff658cea851 )

I want to implement the Extended FAB button in the format mentioned on the material website (https://kstatic.googleusercontent.com/files/8f9b57829c943c97be7c4b2485cf678f041dfe7c7ef523cfb2e97f1aeee21431f83d98cc07befeeed904fabb258298e3a7ac95f9da5d3da7a4adcff658cea851)

https://material.io/components/buttons -floating-action-button#t​​ypes-of-transitions

请提供有关如何实现相同效果的帮助.

Kindly help on how to achieve the same.

推荐答案

您可以使用例如在您的布局中定义:

For example define in your layout:

<androidx.coordinatorlayout.widget.CoordinatorLayout 
      android:id="@+id/root"
      ..>

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/end_card"
        android:visibility="gone" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        .. />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

然后只需定义MaterialContainerTransform:

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showEndView(fab);
        }
    });

具有:

private void showEndView(View startView) {


        // Construct a container transform transition between two views.
        MaterialContainerTransform transition = new MaterialContainerTransform();
        transition.setScrimColor(Color.TRANSPARENT);
        transition.setInterpolator(new FastOutSlowInInterpolator());
        //set the duration....

        //Define the start and the end view
        transition.setStartView(startView);
        transition.setEndView(endCard);
        transition.addTarget(startView);

        // Trigger the container transform transition.
        TransitionManager.beginDelayedTransition(root, transition);
        if (startView != null) {
            startView.setVisibility(View.INVISIBLE);
        }
        if (endCard != null) {
            endCard.setVisibility(View.VISIBLE);
        }
    }

注意:它至少需要版本1.3.0-alpha01.

这篇关于如何在扩展浮动操作按钮上实现菜单显示并单击android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆