Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clicking logo does not trigger onOptionsItemSelected #29

Open
LorneLaliberte opened this issue Jun 1, 2011 · 5 comments
Open

Clicking logo does not trigger onOptionsItemSelected #29

LorneLaliberte opened this issue Jun 1, 2011 · 5 comments

Comments

@LorneLaliberte
Copy link

The documentation for ActionBar.NAVIGATION_MODE_STANDARD states:

    /**
     * Standard navigation mode. Consists of either a logo or icon and title
     * text with an optional subtitle. Clicking any of these elements will
     * dispatch onOptionsItemSelected to the host Activity with a MenuItem with
     * item ID android.R.id.home.
     */

...however this does not seem to occur in my app. The highlight colour is shown, but it does not reach either onOptionsItemSelected or onMenuItemSelected.

The same thing occurs in both NAVIGATION_MODE_STANDARD and NAVIGATION_MODE_LIST.

Note also that android.R.id.home is not resolvable in 2.3.3 (API level 10), it's only available since 3.0 (API level 11 or higher).

@johannilsson
Copy link
Owner

The documentation needs to be updated on this, the id should be R.id.actionbar_item_home instead of android.R.id.home. Clicks on the title is supported via setOnTitleClickListener.

This patch seems to do the trick for the logo, please review it and see how it works for you.

diff --git a/actionbar/src/com/markupartist/android/widget/ActionBar.java b/actionbar/src/com/markupartist/android/widget/ActionBar.java
index dcf40f2..13c44b7 100644
--- a/actionbar/src/com/markupartist/android/widget/ActionBar.java
+++ b/actionbar/src/com/markupartist/android/widget/ActionBar.java
@@ -378,6 +378,14 @@ public class ActionBar extends RelativeLayout {
             mHomeUpIndicator.setVisibility(getDisplayOptionValue(DISPLAY_HOME_AS_UP) ? View.VISIBLE : View.GONE);
             mHomeLogo.setVisibility(usingLogo ? View.VISIBLE : View.GONE);
             mHomeView.setVisibility(usingLogo ? View.GONE : View.VISIBLE);
+
+            if (usingLogo) {
+                Action homeAction = findAction(R.id.actionbar_item_home);
+                if (homeAction != null) {
+                    mHomeLogo.setTag(homeAction);
+                    mHomeLogo.setOnClickListener(mActionClicked);
+                }
+            }
         } else {
             mHomeUpIndicator.setVisibility(View.GONE);
             mHomeLogo.setVisibility(View.GONE);

This is how I configured the action bar:

ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setHomeLogo(R.drawable.logo_title);
actionBar.setHomeAction(actionBar.newAction(R.id.actionbar_item_home));
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);

The normal icon should work as intended, you can see an example of it here:

https://github.com/johannilsson/sthlmtraveling/blob/master/src/com/markupartist/sthlmtraveling/BaseActivity.java#L43

@JakeWharton
Copy link
Contributor

API documentation for the methods whose signatures match the native action bar have been copied verbatim from Android 3.1 so there may be a few differences. It should definitely be given a looking over before merging to master.

@LorneLaliberte
Copy link
Author

@johannilsson, yep that patch takes care of both issues here (tested in NAVIGATION_MODE_LIST).

  • I actually have no pressing need to use the logo, I was just testing a static helper method.

Thanks!

@JakeWharton, yeah I recognized some of that text from http://developer.android.com/guide/topics/ui/actionbar.html. :)

@adiktz
Copy link

adiktz commented Jan 11, 2012

That patch worked...!!! Thanks...!!!

@adiktz
Copy link

adiktz commented Jan 11, 2012

One more thing...!!! Can I disable click on the home icon...??? I mean it should not show the changed background when it is pressed...!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants