简体   繁体   English

Android Action Bar Logo主页按钮

[英]Android Action Bar Logo Home Button

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. 我正在开发一个Android应用程序,我正在寻找操作栏左侧的徽标菜单按钮。 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. onOptionsItemSelected但这不适合我。

Is there a way to change or find the correct ID for this logo as im starting to think R.id.home is incorrect 有没有办法更改或找到此徽标的正确ID,因为我开始认为R.id.home不正确

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. 我认为这应该工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM