Let BottomSheetDialogFragment transparently transmit click events

It's hard to say. It's actually very difficult. It would be even better if they were embedded together. . But often this requires writing a lot of code

Idea: Click on the dialog to record the coordinates and send them back to the activity, then the activity clicks on the coordinates again

. . It is very difficult to give you ideas that you can't do. .

let's start

define a click method

import android.os.SystemClock
import android.view.MotionEvent
import android.view.Window

object ClickUtils {
    inline fun <reified T : Window.Callback> clickPx( view: T, x: Float, y: Float) {
        // 使用坐标模拟点击事件
        val downEvent = MotionEvent.obtain(
            SystemClock.uptimeMillis(),
            SystemClock.uptimeMillis(),
            MotionEvent.ACTION_DOWN,
            x,
            y,
            0
        )
        val upEvent = MotionEvent.obtain(
            SystemClock.uptimeMillis(),
            SystemClock.uptimeMillis(),
            MotionEvent.ACTION_UP,
            x,
            y,
            0
        )

        view.dispatchTouch

Guess you like

Origin blog.csdn.net/mp624183768/article/details/130534061
Recommended