Actionbar Sherlock: Setting and hiding title bar - android

I'm new to ActionBarSherlock, and am having two problems:
First, I just want to be able to set the title of the action bar, but it doesn't work when I call it like this:
final ActionBar actionBar = (ActionBar) findViewById(R.id.actionBar);
actionBar.setTitle("test title");
Where the corresponding xml object looks like this:
<com.myapp.prototype.ActionBar
android:id="#+id/actionBar2"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
(This is modeled after the github example: https://github.com/johannilsson/android-actionbar/blob/master/actionbarexample/src/com/markupartist/android/actionbar/example/HomeActivity.java). In other places on the web, I see reference to getSupportActionBar(), but I'm not clear how or where to call this.
Second, in another place I just want to be able to hide the Activity's title bar altogether. I'm trying to do this by calling:
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
but I can't even get this to compile. The error I'm getting is:
"The method setDisplayShowTitleEnabled(boolean) is undefined for the type
ActionBar."
In both cases, I guess the Actionbar Sherlock overrides are involved in the problem. Any suggestions how to make this work?
Thanks very much.

Setting the ActionBar title
setTitle("Title")
Hiding and showing the ActionBar
getSupportActionBar().hide();
getSupportActionBar().show();

You seem to be mixing up two different ActionBar implementations. ActionBarSherlock is an extension of the compatibility library provided by Google. The methods used with ActionBarSherlock are almost identical to the native ActionBar found in Android 3.0+ http://actionbarsherlock.com/
The Github link provided (and code you are using) is a custom implementation of an actionbar https://github.com/johannilsson/android-actionbar.
I would advise you use ActionBar sherlock and follow the usage guide here http://actionbarsherlock.com/usage.html
There is also an ActionBarSherlock getting started video here http://www.youtube.com/watch?feature=player_embedded&v=4GJ6yY1lNNY

You need to import com.actionbarsherlock.view.Window so that it secretly uses the long version of this method.

Related

Toolbar bug with method setTitle

I am using this two methods in my toolbar:
toolbar.setTitleTextColor(getResources().getColor(R.color.ColorPrimary));
getSupportActionBar().setTitle("title");
The reason for using getSupportActionBar is because toolbar.setTitle("title"); is not working.
This is a bug?
It is the correct behavior.
You can find more info here.
Check the Chris Banes answer. Chris is working on the Android support libraries at Google.
So we've decided that the current behavior is correct. Once you call setSupportActionBar(Toolbar), the Action Bar is then responsible for handling the title, meaning that you need to call getSupportActionBar().setTitle(...) to set a custom title.
Then use:
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("My title");

How can i remove default TITLE Bar in th android application?

Am new to this tech.
I am trying to build an application,in that i want to Remove default Title bar,and want to add my customised title bar.
Thanks in advance
It's called ActionBar in android. To remove it completely, you have to use a theme which doesn't contain ActionBar like Theme.NoTitleBar or Theme.AppCompat.NoActionBar if you're using AppCompat support library.
You need a custom ActionBar to achieve this.
Please consider reading this training and also this tutorial

Disign Actionbar or create something like it

I want to create an ActionBar like in the picture or to create something like it.
https://drive.google.com/folderview?id=0B6Cz2zvfARSdOHJKSEppSzd6ZHM&usp=sharing
You want to change the style of your ActionBar.
See tutorial on adding buttons.
If you want to support pre-Honeycomb versions of the OS, you will need to start by using the ActionBar compat library.

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

ActionBarCompat: Set Navigation Mode

I'm using ActionBarCompat in my project.
The problem I have now is that I need a spinner to show in the actionbar. A standard ActionBar can use .setNavigationMode(ActionBar.NAVIGATION_MODE_LIST) but this is unavailable in the action bar compat code.
Is there a way around this? What are other options (besides a layout redesign.)
There is no way to do this in the code provided by ActionBarCompat.
It provides an ActionBar in it's most basic form for use by all platforms.
A better alternative is useing ActionBarSherlock. The setup very similar and more functionality is available out of the box.
http://actionbarsherlock.com/

Categories

Resources