HomeAsUp Button has no effect in Android 4.2.2 with Appcompat 21.0.0

萝らか妹 提交于 2019-11-30 16:10:49
Neil MacMillan

I've done some similar research into the issue that I would like to contribute here. I can confirm that with without any items in the menu, the home/up event is not fired in Android 4.2.2 when using the support Toolbar.

The same issue is present in the latest version of the support library, 21.0.2.
manifest settings of parentactivity and meta parentactivity have no effect.
manipulating settings via getSupportActionBar().setXXX() have no effect.
The only "workaround" I can think of is to use toolbar.setNavigationOnClickListener() to get the event.

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) {
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(ToolbarActivity.this, "Up clicked", 
                Toast.LENGTH_SHORT).show();
            NavUtils.navigateUpFromSameTask(ToolbarActivity.this);
        }
    });
}

This way at least other platforms can function properly, and v17 can have this weird workaround so the toolbar isn't completely broken on jellybean mr1.

I've filed this as a bug with Google which can be tracked here: https://code.google.com/p/android/issues/detail?id=81528

Mohammed Ali

Inside your PrefsActivity add:

getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);

Also see the docs for a discription of these functions and other functions to serve your purpose.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!