I'm currently developing an android application and i'm looking to make the logo on the left of the action bar a menu button. I have enabled the logo using the code
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
from my research I should be able to make this aa menu button by using the code
if (id == R.id.home) {
Intent i = new Intent(getApplicationContext(), MenuActivity.class);
startActivity(i);
}
in onOptionsItemSelected
but this is not working for me.
Is there a way to change or find the correct ID for this logo as im starting to think R.id.home
is incorrect
I think with enabling your home button with
actionBar.setDisplayHomeAsUpEnabled(true);
and then
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
//fire intent or whatever you require.. do over here
return true;
default:
return super.onOptionsItemSelected(item);
}}
I think this should work fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.