Customize the action bar of android app with an image - android

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:
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.
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.

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

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.

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");

Related

How to add a custom title bar with an image as background in android studio

I have found several answers on here as to how to change the background color and add a custom icon to the title bar in android studio but am having difficulties finding an answer for how to use a custom image as the background instead of just a color in the title bar. Any help would be much appreciated. Thanks.
sadly you cannot add images as the background on both the header and textView/webView that's why you don't see any apps on android with image backgrounds. you could try using html instead of xml, like:
replace colors.xml, styles.xml, ect with colors.html, styles.html, ect
but i doubt that will work. hopefully they will add this feature later in the android sdk.

Styling the "Share" action menu

I'm trying to add a "Share button" to my app, but I haven't found a way to manage the styling of the ActionMenu displayed to choose the app to share content to.
Currently it appears as in this screenshot:
However, I'd like to change the background color and the text color to make them reflect the ones in the ActionBar: which are the style properties that handle these two colors?
I would suggest follow this tutorial and using the linked tool:
http://blog.stylingandroid.com/styling-the-actionbar-part-3/
Jeff Gilfelt Android Action Bar Style Geberator tool
Quick mockup below, to prove it's very relevant and helpful in the direction of solving your question:

ActionBar (Sherlock) displaying icon with number of messages on top

I am working with ActionBar and since I have Messaging functionality I wanted to notify user in ActionBar if he has any unread messages. It would look kinda like this:
However, I can't seem to find if this is supported. So, does anyone know if this is supported and how I would add an icon over existing ActionBar item in this fashion?
The best approach to this would be to create a modified drawable yourself and set it as the source of that particular ActionBar icon. To do this you can call invalidateOptionsMenu() and re-set the icon from within onCreateOptionsMenu(Menu). You can use a LayerDrawable to superimpose the number on top of your actual icon drawable.
I do not think it is something built-in in the API, however there is a simple implementation for a badge-button that might help you

Android application - three questions

I am writing an Android application at the moment, no knowledge of java what so ever, except what I have learnt in the last 5 hours. I've managed to implement a two screens and a nice looking layout.
I have three questions:
How do I set the Action Bar on Honeycomb to be transparent like in the Google Maps application? I want to be able to partially see the background graphic through it.
What code to use to empty five edit texts and a textview on button click? I've read something about a viewgroup, but I have no idea how to implement that...
I have a linearlayout with a tablelayout centred horizontally and vertically inside it, and eleven table rows in that. How do I set a partially transparent black as a sort of fill colour for the tablelayout without ruining the background of the linearlayout? Every time I try to set a fill colour it blacks out the entire background image of the layout surrounding it as well.
Plain english would be preferable because I am so new to this.
Thanks heaps for any replys, have a great day.
For the first question, I think you can do like below:
In the onCreate() method, before the setConentView() add:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
The Android system will automatically set background fill the whole screen.
create a transparent sharp "mysharp.xml"like below:
<?xml version="1.0" encoding="utf-8"?>
<shape>
<solid android:color="#55000000" />
</shape>
set the action background
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.mysharp));
you can also declare action bar overlay in xml by
<item name="android:windowActionBarOverlay">true</item>
just like here http://developer.android.com/resources/samples/HoneycombGallery/res/values/styles.html
Answer to your 1st question: You can implement a theme on the HoneyComb action bar. Check this link for more info. The color would be something like this: #29000000.
The first hex 2-digit(#29) represents alpha channels of color and set opacity. If value is “00” that means 100% transparent. if value is set it will be opaque, it can be any value in 00 to FF.
More links on styling the Action Bar:
http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
Example project is to be found here:
http://p-xr.com/customizing-the-action-bar-in-honeycomb/
In my Android 3 application I used
// Makes Action Bar Transparent
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
actionBar = getActionBar();
actionBar.setBackgroundDrawable(null);
// END
and now the action bar is 100% transparent, Except for the stuff I add to it of course :)
Cheers

Applying a custom title bar for the entire application

I actually want to apply a custom title bar (kind of like the Action Bar), but since i'm developing for Froyo, I actually need to have it in a xml file. The trivial way to do this is to just write the code to create the title bar in each of the activities.
I did search around for some efficient ways and found this on SO
Similar Problem
There are 2 solutions proposed over there, but I am having problems in implementing them.
To include the layout of your title bar in the layout of all the Activities. My question is say I have a sample layout as follows, where should the include tag go and do I need to use Theme.NoTitleBar theme for the application in order to get it working?
To subclass Activity and then derive all of my Activities from that. Should the custom Title bar creation method be defined in the onCreate method of the subclassed Activity. Because if I do this, the custom title bar does appear, but it appears blank. No buttons,etc.. are present on it.
Thanks in advance for any help you provide
The tag belongs inside the top level view container (linear layout/relative layout). Yes use NoTitleBar so you don't have the Android provided title bar in your app window.
There is obviously an issue with your code there, with out any code in your post I cannot help you.

Categories

Resources