pull/1678/head
kunfei 3 years ago
parent 717a3ec53e
commit ee71e76397
  1. 10
      app/src/main/java/io/legado/app/utils/MenuExtensions.kt
  2. 8
      app/src/main/res/layout/view_action_button.xml

@ -1,9 +1,12 @@
@file:Suppress("unused")
package io.legado.app.utils
import android.annotation.SuppressLint
import android.content.Context
import android.view.Menu
import android.view.MenuItem
import android.widget.ImageButton
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.view.menu.MenuItemImpl
import androidx.appcompat.view.menu.SubMenuBuilder
@ -55,4 +58,11 @@ fun Menu.applyOpenTint(context: Context) {
item.icon?.setTintMutate(defaultTextColor)
}
}
}
fun MenuItem.setOnLongClickListener(menu: Menu, function: () -> (Unit)) {
setActionView(R.layout.view_action_button)
actionView.findViewById<ImageButton>(R.id.item).setImageDrawable(icon)
actionView.setOnLongClickListener { function.invoke(); true }
actionView.setOnClickListener { menu.performIdentifierAction(itemId, 0) }
}

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item"
style="?android:attr/actionButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="ContentDescription" />
Loading…
Cancel
Save