直播源码网站,实现对话框的左滑动删除
直播源码网站,实现对话框的左滑动删除的相关代码
在你项目的 build.gradle 添加:
implementation 'io.github.sakurajimamaii:VastSwipeListView:0.0.1'
快速开始
在你的布局中添加 VastSwipeListView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SlideActivity">
<com.gcode.vastswipelayout.view.VastSwipeListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"/>
</LinearLayout>
使用 VastSwipeMenuItem 来定义你的菜单项,调用 VastSwipeMenuMgr 内的方法将菜单项添加进去
我们这里以定义撤销项举例
val deleteItem = VastSwipeMenuItem(this@SlideActivity)
deleteItem.setBackgroundByColorInt(0xFF1e90ff)
deleteItem.setTitleByString("撤销")
deleteItem.setTitleColorByColorInt(Color.WHITE)
deleteItem.setIconByResId(R.drawable.ic_delete)
deleteItem.setClickEvent { item: VastSwipeMenuItem, position: Int ->
run {
Toast.makeText(this@SlideActivity, "${item.title} $position", Toast.LENGTH_SHORT)
.show()
}
}
swipeMenuMgr.addLeftMenuItem(deleteItem)
准备列表项数据的adapter
val listViewAdapter = ListViewAdapter(this, R.layout.listview_item, lists)
将设置好的 VastSwipeMenuMgr 和列表项 Adapter 传给 VastSwipeListView
vastSwipeListView.setSwipeMenuMgr(swipeMenuMgr)
vastSwipeListView.adapter = listViewAdapter
vastSwipeListView.onItemClickListener =
AdapterView.OnItemClickListener { _, _, arg2, _ ->
Toast.makeText(
context,
"位置 " + arg2 + " >>> value:" + lists[arg2],
Toast.LENGTH_SHORT
).show()
}
以上就是直播源码网站,实现对话框的左滑动删除的相关代码, 更多内容欢迎关注之后的文章