For automated testing purposes I need to add ID to toolbar's BACK / MENU button view.
I tried to add id using getChildAt
and setId
but the id is still not set when I check the view hierarchy. android.R.id.home
menu id does not work in my case. I need id that is set for the view when I check the view hierarchy with Layout inspector. Only then the id can be used for automated UI tests.
Could you suggest a way to do this?
toolbar's BACK / MENU button has already id android.R.id.home
you can use this id
to perform action on that use below code
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
Toast.makeText(context, "Backarrow pressed", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With