以下是我在创建
上的活动 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// set subtitle if there is a filter
toolbar.setSubtitle(MySharedPref.getStringTitile(this));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, RealtyListFragment.newInstance("test", "test"))
.addToBackStack(null)
.commit();
}
然后在onOptionsItemSelected中,当我点击HOME / up按钮时,我什么都没有。
Log.d("!!!!!!!!!YEP","YEP");
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_search) {
FilterDialogFragment dialogFragment = new FilterDialogFragment();
dialogFragment.show(getSupportFragmentManager(), "dialog");
return true;
}
if (item.getItemId() == android.R.id.home) {
Log.d("!!!!!","Home pressed");
}
return super.onOptionsItemSelected(item);
按照我的方式,这根本没有用。
@Override
public boolean onOptionsItemSelected(MenuItem menuItem){ if(menuItem.getItemId()== android.R.id.home){ Timber.d(“Home press”); } return super.onOptionsItemSelected(menuItem); }