Android how to make clickable logo icon in actionbar?

我们两清 提交于 2019-12-19 02:03:21

问题


I`m using SherlockActionBar for my application. In my manifest I define icon for logo and launch.

    android:icon="@drawable/ic_launcher"

How to make it clickable and handle the event of it`s pressing? I want to be able to back to my dashboard by pressing the logo.


回答1:


Use

actionBar.setDisplayHomeAsUpEnabled(true);

with

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        //Do stuff
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}



回答2:


You can read more about the home button here http://developer.android.com/guide/topics/ui/actionbar.html#Home

It explains how to clear previous the stack of previous activities and has some more links to best practices on navigation using the home button.



来源:https://stackoverflow.com/questions/11030204/android-how-to-make-clickable-logo-icon-in-actionbar

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