6

I want to enable the navigating up function in the ActionBar and have followed the document about this at:http://developer.android.com/guide/topics/ui/actionbar.html

But when I check my app (on android 4.0), the app icon does not show up, instead only a left caret is shown.

I have checked the android manifest file, the java file and layout file, but still have no idea of how to get it work....

Here is the AndroidManifest.xml:

...
<activity
        android:name="com.test.HelpActivity"
        android:label="@string/help"
        android:parentActivityName="com.test.HomeActivity"
        android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
        android:screenOrientation="portrait" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.test.HomeActivity" />
</activity>
...

And here is the Java code:

...
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

public class HelpActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_help);

        ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}

}

Thank you for help!

=====UPDATE=====

I did a few more testing, and here is what I got:

on an Android Emulator (2.3), it works perfect.

on an Android Emulator (4.1.2), it works perfect.

on an Android Emulator (4.0), it seems fine, but when I click the home/up button, nothing happens and logcat displays: bad parentActivityName 'HomeActivity' in manifest

on my phone (4.0.3), only left caret is displayed, yet navigation works fine.

on an Android Emulator (4.3), it works fine, but the focusable area becomes the app icon + app title. (That is when I press anywhere within this long area, it is highlighted and navigation up event is triggered)

I am now totally lost... Guess it could be some bug in certain android versions.

Qianqian
  • 2,104
  • 18
  • 28
  • Hi. Did you find a solution ? I might be in the same case. Tried everything but the icon won't show. I'm out of ideas... – DEIONaLiMs Jan 02 '15 at 16:10
  • @DEIONaLiMs, No I have not got a solution and it looks like a bug in the appcompat actionbar. I just gave it up in the end and maybe you can try to use the Sherlock ActionBar if you have to get rid of this error. – Qianqian Jan 07 '15 at 01:26

4 Answers4

2

add this line below actionBar.setDisplayHomeAsUpEnabled(true);
it works for me

 actionBar.setDisplayShowHomeEnabled(true);
 actionBar.setIcon(R.drawable.ic_launcher);
Sumit
  • 1,022
  • 13
  • 19
  • Thank you. But trust me, I tried it and it did not work. The good thing is I now use Toolbar instead and do not need the icon any more, with the latest appcompat. – Qianqian Dec 17 '14 at 01:42
1

I think in android 5 and API 21 we can't use app icon for up action.
if your appcompat support library is v7 rev21 i think you can't use the app icon at least for up action. but u can use it instead of top left caret or you can use app icon right of that caret although if u click it nothing happen.

I have two app completely like that trainings in one of them i use the older appcompat v7 and minSdkVersion="11" and i never added getSupportActionBar().setDisplayHomeAsUpEnabled(true);
to it but app have app icon and no problem . but in another app i update my support library a few day ago to rev21 and of course this app's minSdkVersion is "8" but this app hasn't actionBar icon for Up action and if you add top code to it you do nothing. I search many of sites and just i understand is that in material design google removed app icon for up action because of increasing space on actionbar and etc. You can see this line
"When using the Material themes (default in API 21 or newer) the navigation button (formerly "Home") takes over the space previously occupied by the application icon. Apps wishing to express a stronger branding should use their brand colors heavily in the action bar and other application chrome or use a in place of their standard title text."
in this page http://developer.android.com/reference/android/support/v7/app/ActionBar.html
I think. thanks.

hitman snipe
  • 1,081
  • 7
  • 5
0

Following enter link description here

I have added in the setUp of the NavigationDrawerFragment

        Toolbar toolbar = (Toolbar) ((Activity)mCallbacks).findViewById(R.id.action_bar);
    if(toolbar!=null){
        toolbar.setLogo(R.drawable.ic_launcher);
    }   

also there seems no need for

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

I am using the last support library 21.0.3

hth

Community
  • 1
  • 1
Čikić Nenad
  • 392
  • 5
  • 13
-2

Thats weird, well you can use this

getActionBar().setDisplayUseLogoEnabled(useLogo)

where useLogo its true or false, you can even use another drawable as action bar icon with this

getActionBar().setLogo(logo)

where logo its a drawable

Javier
  • 1,469
  • 2
  • 20
  • 38
  • I indeed tried the logo, although I did so by adding the attribute in the AndroidManifest file with the corresponding attribute. But I will try this also. – Qianqian Apr 15 '14 at 00:24