I want to set title and subtitile of my action bar before compile time. I got a way to do it like this:
ActionBar ab = getActionBar();
ab.setTitle(\"My Title
You can set the title in action-bar using AndroidManifest.xml
. Add label to the activity
<activity
android:name=".YourActivity"
android:label="Your Title" />
supportActionBar?.title = "Hola tio"
supportActionBar?.subtitle = "Vamos colega!"
<activity android:name=".yourActivity" android:label="@string/yourText" />
Put this code into your android manifest file and it should set the title of the action bar to what ever you want!
Try This:
In strings.xml add your title and subtitle...
ActionBar ab = getActionBar();
ab.setTitle(getResources().getString(R.string.myTitle));
ab.setSubtitle(getResources().getString(R.string.mySubTitle));
For an activity you can use this approach to specify a subtitle, along with the title, in the manifest.
Manifest:
<activity
android:name=".MyActivity"
android:label="@string/my_title"
android:description="@string/my_subtitle">
</activity>
Activity:
try {
ActivityInfo activityInfo = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
//String title = activityInfo.loadLabel(getPackageManager()).toString();
int descriptionResId = activityInfo.descriptionRes;
if (descriptionResId != 0) {
toolbar.setSubtitle(Utilities.fromHtml(getString(descriptionResId)));
}
}
catch(Exception e) {
Log.e(LOG_TAG, "Could not get description/subtitle from manifest", e);
}
This way you only need to specify the title string once, and you get to specify the subtitle right alongside it.
This is trivial one-liner in Kotlin
supportActionBar?.title = getString(R.string.coolTitle)