Applying a custom title bar for the entire application - android

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.

Related

Customize the action bar of android app with an image

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

Custom titlebar (summary) in PreferenceActivity

As the title suggests I want to create a custom title bar for a PreferenceAcitvity.
I need to add a summary below the title. Currently it will only display a title, but I need a sub-title, just like any Preference can have a summary.
I have read loads of questions here, like this and this, but these all do something different; it's not possible to include a summary for the title with the first method. Creating a custom layout for every Preference also doesn't seem the wisest option, and is loads of meaningless work (I have tons of PreferenceActivity's. I am looking into extending something.
Also, I want to keep the default behaviour as much as possible, so I am looking into ways of adding a TextView to the default layout located in android-sdk-windows\platforms\android-16\data\res\layout\screen_title.xml
So I thought I would apply this layout to the method in the second Q, but now I run into the problem of resource id's used in the screen_title.xml file that aren't public.
I'm running out of ideas...anyone got some fresh ones?
EDIT:
I found a solution thanks to the accepted answer below.
To clarify a bit further: the method getSupportActionBar() in the answer isn't in the SDK, but comes from ActionBarSherlock.
This is a compatibility library to enable the ActionBar and FragmentActivity (amongst other things) on pre API 11 applications/ devices. It's quite a heavy library, around 11mb, so you will have to think about if it's worth adding 11mb to your application just to have a summary/ subtitle in your preference screen's. On the other hand, this ofcourse also allows you to implement the other features of the library, such as actually creating an action bar (and or menu).
If you are talking about Actionbar then you can do this:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setSubtitle("Test Subtitle");

How is skype android app doing it?

If you have seen the skype android app, then you may have noticed that when skype moves from one activity to another, the top bar remains in place while the rest of the page slides out and the new activity comes in.
So how are they doing it? I want to do something like that.
Fragments can do what you wan't, and a lot more
In skype.. They are using Tab Activity...
Refer : http://developer.android.com/reference/android/app/TabActivity.html
Android TabHost Tutorial
Also if you want to use a single title through out the applciation :
You can define a title_layout.xml... & include it in the top of all your layouts like
<include layout="#layout/title_header"/>
You need to create a custom view which will act as your Tab Bar.
After creating your custom tab bar use it in whatever activity as you want.
Check this for more info on custom views.
http://developer.android.com/guide/topics/ui/custom-components.html

Android Navigation Bar

I've done a great amount of searching and I can't seem to find anything that helps me. I'm new to Android programming (I do know Java though), and I am working on an app that deals with dynamic content being downloaded from a server. I would like to have a bottom navigation bar, that is persistent throughout the app. This nav bar will consist of 5 buttons, that when clicked will open a new activity. However I would like the activity to be loaded in the content area above the nav bar.
So basically I will have a layout that contains a content view and the nav controller. The nav controller should never change...the content view should load a new activity upon nav button click. Does anyone have any ideas? Thanks.
You will have to create a common layout for the navigation bar , and include it in every layout of the activity. use "include" tag in the xml to do this. please have a look at the discussion below, it may help you.
Common buttons or tabs at bottom for every activity
Have a look at this project: http://code.google.com/p/androidtabs/
You might want to consider looking at Fragments since the TabActivity is deprecated. You would need to download a compatibility package in the SDK in order to use it on pre-honeycomb devices. It should be able to do exactly as you want.

Fixed action bar similar to the Facebook app

I have implemented the action bar (not the quick action bar) in my app. The action bar is based on the one used in the Google IO app and the Facebook app. I am stumped though, trying to understand how to keep the action bar fixed. When an activity needs scrolling, the action bar needs to be remain fixed. Can anyone help with this problem?
Some good stuff in Jon's post, but if you're just looking for the simple answer to work with your existing layouts/activities, just use a vertical LinearLayout with the first child as the titlebar and the second as the ScrollView, setting the ScrollView height to fill_parent (or setting fillViewport to true). Alternatively, use a RelativeLayout with the scrollview set to layout below the title, or with a top margin on the scrollview equal to the height of the title bar.
I'm developing an open-source app that is adapted from Google IO. I made a generic version of the titlebar that they used - called CustomTitlebarActivity which subclasses Activity.
As an example, I'll refer you to my HomeActivity implementation which subclasses CustomTitlebarActivity; since I abstract the titlebar away from the activity's layout, you can easily add a ScrollView below it that will not scroll the titlebar out of view.
An added benefit to this design choice is a lot more code re-use than Google IO had, with some ..quirks that are easily circumvented. I won't go into that in more detail here though.
HomeActivity
res:
http://code.google.com/p/electricsleep/source/browse/beta/res/layout/activity_home.xml
src:
http://code.google.com/p/electricsleep/source/browse/beta/src/com/androsz/electricsleepbeta/app/HomeActivity.java
CustomTitlebarActivity
res:
http://code.google.com/p/electricsleep/source/browse/beta/res/layout/titlebar.xml
src:
http://code.google.com/p/electricsleep/source/browse/beta/src/com/androsz/electricsleepbeta/app/CustomTitlebarActivity.java
Also, I have one activity that has a scrollview inside it, (though it is inside a ViewFlipper) in case you have trouble. Check out the res:
http://code.google.com/p/electricsleep/source/browse/beta/res/layout/wizard_welcome.xml

Categories

Resources