简体   繁体   English

如何在onLongPress中显示自定义浮动选项菜单并按住recyclerView的项目?

[英]How to show a custom floating option menu in onLongPress and hold item of recyclerView?

I am trying to achieve this view in my native android app in item long-press from the list:我试图在我的本地 android 应用程序中长按列表中的项目来实现此视图:

项目长按浮动选项菜单

My list is:我的清单是:

    <androidx.recyclerview.widget.RecyclerView
          android:id="@+id/chatList"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="24dp"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/chat_toolbar" />

List initialization java code:列表初始化 java 代码:

RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(ChatList.this);
    chatList.setLayoutManager(mLayoutManager);
    chatList.setItemAnimator(new DefaultItemAnimator());
    chatList.setAdapter(chatAdapter);

You can use android's Popup Menu and inflate custom layout in this to get your expected result.您可以使用 android 的Popup Menu并在此扩展自定义布局以获得您的预期结果。 This is a reference blog for this, have a look.这是一个参考博客,看看。

or, there are also third-party libraries available https://github.com/skydoves/PowerMenu或者,也有可用的第三方库https://github.com/skydoves/PowerMenu

Feel free to ask if something is unclear.随意询问是否有不清楚的地方。

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

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