0

I am creating an android application and I want to customize the look and feel of the action bar of the application. For my project I am using actionbar sherlock. Currently my app is looking like this: Current look of the application

I want to remove the logo of the application and also the application title from the action bar and replace it with the following image. custom image for actionbar

Is there any way to accomplish this. I have read that we have to use the style tag to do this. But since I am new I don't know where to write the style tag and how to implement this. Please help...

EDIT The width of the new image should be adjustable i.e. my requirement is that its width should cover half of the action bar

All I want to achieve is something like this application which is available in play store. final result

ganapathy
  • 1,407
  • 3
  • 13
  • 20

3 Answers3

1

Update your AndroidManifest.xml tag to include the :icon attribute.

See the developer docs for more information.

Example:

<application
    android:logo="@drawable/my_logo"
    ....>

</application>

Another nice example, for use with a theme/style can be found here.

To hide the title text shown on the action bar see this post's accepted answer. You'll need to have a custom style applied to the action bar to hide the text. If you also want the icon to be larger than the allowed space, you'll need to also set the background of the action bar as explained by @Eenvincible.

It's also worth noting that you're breaking a lot of Android Design Guidelines. It'd be easier for you and better for your users to simply set the right icon/title and move on with the standard ActionBar look/feel. Worth a look: Android Design Patterns - ActionBar.

Community
  • 1
  • 1
Grant Amos
  • 2,256
  • 17
  • 11
  • if i just change the android:logo to my_logo won't it just change the android bot which appears in the actionbar. What I want is that both the title and the image get replaced by the new image – ganapathy Mar 14 '14 at 19:27
  • I have added an image in my question. All i want to achieve is that type of actionbar. Does that still violate Android Design Guidelines? – ganapathy Mar 14 '14 at 19:46
  • There's nothing preventing you from going agains the guidelines, they're merely a suggestion. Personally, I think it goes against the look and feel the Android design team is pushing for, but that's for you to do decide. Read over the link I provided as well as the other resources in their Design docs and decide what you'd like to do. The links i've provided show you how to hide the title, to hide the icon use this ( http://developer.android.com/reference/android/app/ActionBar.html#setDisplayShowHomeEnabled(boolean) ) function in your onCreate, finally specify a background like @Eenvincible – Grant Amos Mar 14 '14 at 19:58
1

Just use this line in your onCreate method:

Drawable d=getResources().getDrawable(R.drawable.action_bar_background);
    getActionBar().setBackgroundDrawable(d);

That will change the background of your actionbar to whatever image you want.

Of course it is always important to have different sized images for different device sizes.

I hope it helps

Eenvincible
  • 5,641
  • 2
  • 27
  • 46
0

What you are seeing is actually the default icon. Replace ic_launcher.png file from the following folders(if it exists there) with your image.

  • /res/drawable
  • /res/drawable-ldpi
  • /res/drawable-mdpi
  • /res/drawable-hdpi
  • /res/drawable-xdpi
  • /res/drawable-xxdpi

Also rename your image file to ic_launcher.png

To edit the text on right of icon, you can use:

getSupportActionBar().setTitle("ANY TEXT HERE");
novic3
  • 106
  • 5
  • Please check the edit section. I want to change the size of the image, i.e.it should cover almost half of the actionbar – ganapathy Mar 14 '14 at 19:31