views:

353

answers:

2

This question has been asked before - but with no satisfying answer at all! So I'm trying it again.

I want to give my application launcher icon (the one that is displayed on the startscreen!) a different, shorter caption. It seems the launcher takes its label from the mainfest section about the main activity's label, as here:

<activity android:name="MainActivity" android:label="@string/app_short_name">
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

I already changed the original reference to my app's name @string/app_name to a different, shorter string resource here.

BUT - big BUT: this also of course changes this activity's default title! And I did not want that to happen, there's enough space for a long application name! Setting the long title again in onCreate using the setTitle(int) method does no good either, because the short name will be visible to the user for a short time, but long enough to notice!

And - please don't answer my question by refering to a custom titlebar... I do not want to go that long way, just because of a stupid string title! It's a pain to draw a custom title bar for so little effect!

Is there no easy way to just give the launcher a different string to display? Thanks for your answers!

Edit: One more reason why having a custom titlebar is a pain is that it will not look like the default titlebar, I would have to explicitly do things to make it look alike on each device! And that can't be a solution if, after all, I don't want a different appearance!

A: 

You can do something like this:

public class FooBar extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // change title
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_title);
    }
}

You'll have to create a custom layout to hold the title. It could be as simple as (called my_title.xml in this case):

<?xml version="1.0" encoding="utf-8"?>
<TextView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="foo bar"/>

In your AndroidManifest.xml file you just have to set the title for the app, which is what is going to be shown in the launcher icon. For your activity you don't need to set a title there.

Cristian
I doubt that that's really true: the application's label is **not** what defines the launcher label-it merely defines how the application is named in the list of installed apps (settings->applications->manage applications) and this label is also taken by Android Market, too. So I don't want to change that.By experimenting I found out it is the activity's title that the launcher takes, too.Apart from that: your solution involves a cutsom title which I don't want! This never looks like the default title bar at all - or I would have to do a lot just to get default behaviour- not good at all!
Zordid
Hmm... it's even worse. I just tried your solution. But, the titlebar does not look like the default at all and, even worse, the default titlebar (showing the short name I don't want to see) is displayed shortly before the custom titlebar appears.Thus: this solution is the same as just setting the title using `setTitle`. :-(
Zordid
+1  A: 

This probably won't satisfy what you want to do, but have you thought about creating a splash screen that displays very briefly (with the default title) and then launches your new actual "main" activity with the title of your choosing using the setTitle(int) method? I have not tried this to see if it works but that might create a pleasant work around that does not show of the less than seamless nature of what you are trying to achieve.

Adriaan