Colton Idle
04/17/2021, 2:07 AMsetContent
in an Activity seems to kill the ability to use Activity.onTouchEvent()
Is this a bug? 🧵Colton Idle
04/17/2021, 2:09 AMclass MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<Button>(R.id.myButton).setOnClickListener {
Toast.makeText(this, "XML BUTTON CLICKED", Toast.LENGTH_SHORT).show()
}
}
override fun onTouchEvent(event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_UP) {
Toast.makeText(this, "ACTIVITY CLICKED", Toast.LENGTH_SHORT).show()
return true
}
return false
}
}
The xml based layout has a button in the top left corner. When I click the button, I see the XML BUTTON CLICKED toast... and anywhere I click in the Activity I see ACTIVITY CLICKEDColton Idle
04/17/2021, 2:13 AMclass MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val context = LocalContext.current
Column(Modifier.fillMaxSize()) {
Button({
Toast.makeText(context, "COMPOSE BUTTON CLICKED", Toast.LENGTH_SHORT)
.show()
}) {
Text("Button")
}
}
}
}
override fun onTouchEvent(event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_UP) {
Toast.makeText(this, "ACTIVITY CLICKED", Toast.LENGTH_SHORT).show()
return true
}
return false
}
}
Which does not work. The activity clicked never shows. But the COMPOSE CLICKED does.
Ideas?Albert Chang
04/17/2021, 2:44 AMonTouchEvent
says
Called when a touch screen event was not handled by any of the views under it.
And ComposeView is intercepting all the touch events.
Colton Idle
04/17/2021, 2:47 AMAlbert Chang
04/17/2021, 2:47 AMAlbert Chang
04/17/2021, 2:48 AMdispatchTouchEvent
.Colton Idle
04/17/2021, 2:50 AMAlbert Chang
04/17/2021, 2:51 AMColton Idle
04/17/2021, 2:54 AM