To change the title of an activity (to show a more custom title for a certain activity than the application title), you can set the new title either through calling setTitle("foo") on the activity or by setting android:label="@string/price_after_rebate" in your activity style.
On latest Android versions - If there are more than one launcher activities and if we don't put this category tag then the activity which is mentioned first in the Android manifest file will get launched as start-up activity.
You can simply call the setTitle() function from within your Activity . It takes either an int (resource ID) or a CharSequence as a parameter. Show activity on this post. For changing Activity title you should use setTitle() of Activity class.
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.
I was looking for the same thing and here's what worked for me.
<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>
This will give a short name to your application launcher icon.
To add a larger name to the application bar you just have to add:
this.setTitle(getResources().getString(R.string.app_name));
to your main activity java file.
Solution of Mark Renouf fails to me (using Nexus 4 and Android 4.4). It fails when using shortcuts, shortcuts use the main activity label instead of the app name. I saw some apps like GMail and Google Keep that works fine. But when you open them, I notice its like a moment between the title is blank and the title appears (which seems better than the app name flashing before setting the title using setTitle()).
So here is the best solution I found:
Create a style where the ActionBar does not show the title/label:
<style name="NoActionBarTitle" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/NoActionBarTitle.ActionBar</item>
</style>
<style name="NoActionBarTitle.ActionBar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">showHome|useLogo</item>
</style>
I'm using a navigation drawer and using a logo (because I use a logo and an icon for my app). You can use whatever but don't use showTitle. Then in the AndroidManifest.xml, set the theme for the MainActivity:
<activity
android:name="com.xx.xxx.MainActivity"
android:logo="@drawable/ic_icon_padding"
android:theme="@style/NoActionBarTitle">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Then, in the onCreate() method of the MainActivity, set the title of your Action Bar:
getActionBar().setTitle(R.string.your_title);
After it, you can call:
getActionBar().setDisplayShowTitleEnabled(true);
Tricky but worth.
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.
For anyone using Support / Appcompat Toolbar via the setSupportActionBar()
method, the Activity title can be set in Toolbar XML:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
app:title="@string/activity_title"
...
/>
This will override application and activity labels set in the manifest.
android.support.v7.widget.Toolbar
I found a workaround for this problem
In manifest.xml
Write your app's name in the android:label
of the launcher(main) activity.
This will make the label of your main activity same as that of the app label.
Then, in the onCreate()
function of your Launcher(main) activity write this statement
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle("main activity label");
}
Here write the label that you want to give to your Launcher(main) activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With