How to set different label for launcher rather than activity title?

Zordid picture Zordid · Aug 15, 2010 · Viewed 97.3k times · Source

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!

Answer

Mark Renouf picture Mark Renouf · Aug 31, 2011

Apparently <intent-filter> can have a label attribute. If it's absent the label is inherited from the parent component (either Activity or Application). So using this, you can set a label for the launcher icon, while still having the Activity with it's own title.

Note that, while this works on emulators, it might not work on real devices, because it depends on the launcher implementation that is used.

http://developer.android.com/guide/topics/manifest/intent-filter-element.html

<activity
  android:name=".ui.HomeActivity"
  android:label="@string/title_home_activity"
  android:icon="@drawable/icon">
  <intent-filter android:label="@string/app_name">
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

Side Note: <intent-filter> can also have an icon attribute, but inexplicably it does not override the icon specified in the Activity. This may be important to you if you plan to use the native ActionBar in SDK 11+, which uses Icon and Logo specified on the Activity.

Added Info: The label is being inherited from Activity and not the Application.

 <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"       
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

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

In this case, app_long_name will be displayed with launcher icon, if we do not put label inside as mentioned above.