Tôi có một thanh hành động có chứa searchview
. Khi người dùng nhấp vào nút tìm kiếm và thu gọn chế độ xem tìm kiếm, thanh tác vụ hiển thị nút quay lại ở bên trái.phát hiện một nút bấm trên thanh hành động trở lại - (OnOptionsItemSelected không gọi khi bấm vào nút thanh hành động trở lại)
Làm cách nào chúng tôi có thể phát hiện khi người dùng nhấp vào nút quay lại này?
Sửa
dựa trên câu trả lời tôi đã kiểm tra tôi OnOptionsItemSelected
nhưng nó không phải là kêu gọi quá. Đây là mã của OnOptionsItemSelected
tôi:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (item != null && id == android.R.id.home) {
if (mNavigationDrawerFragment.isDrawerOpen(Gravity.RIGHT)) {
mNavigationDrawerFragment.closeDrawer(Gravity.RIGHT);
} else {
mNavigationDrawerFragment.openDrawer(Gravity.RIGHT);
}
return true;
}
if (id == R.id.action_search) {
return true;
}
return super.onOptionsItemSelected(item);
}
http://stackoverflow.com/questions/14437745/how-to-override-action-bar-back-button-in-android – codePG