How can I detect a click on the ActionBar title?

android, android-actionbar, onclick, textview, title

Solution

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()`.

Problem

For specific customer requirement, I need to allow the user of my app ( won't be published in Market) to click on the ActionBar title to execute some actions. I have been looking in the Android source, but I am not able to find an ID for the actionBar TextView title. Is there a proper way to handle such clicks?

Original source

Related problems