How can I detect a click on the ActionBar title?

The title is non-clickable AFAIK. The icon/logo is clickable — you’ll get that via android.R.id.home in onOptionsItemSelected(). Conceivably, the title also routes this way, though they don’t mention it and I wouldn’t rely upon it.

It sounds like you want a Spinner for the user to choose the actions to execute. If so, use setListNavigationCallbacks(). If you want to remove the title as now being superfluous, use setDisplayOptions(0, DISPLAY_SHOW_TITLE).

If you want something other than a Spinner on the left side of the action bar, use setDisplayOptions(DISPLAY_SHOW_CUSTOM, DISPLAY_SHOW_CUSTOM) and setCustomView(). Note that this approach is not recommended (“Avoid using custom navigation modes in the action bar”), as it may not work well with phones, particularly in portrait mode.

Another possibility would be to remove the title and use a logo instead of the icon, and in the logo have your “title” as part of the image. The whole logo should be clickable, picked up via onOptionsItemSelected().

Leave a Comment