Vadim L.
Vadim L.

Reputation: 155

app name and main activity title can be different in Android?

Is it possible to have different app name and main activity title ?

I had tried to change manifest file, to find work-around like setTitle() to the ActionBar, but expected result not happens. I think this string must be identical, isn't it ?

Anyone can tell me about this,if can make it,please tell me how to do?Thanks!

UPDATE: snippet from manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.myname.appname"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
        <activity
            android:name=".activities.HomeActivity"
            android:label="@string/title_home_activity"
            android:configChanges="orientation"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:name=".activities.SettingsActivity"
            android:label="@string/title_activity_settings">
        </activity>
        <activity android:name=".activities.DetailsPageActivity"
                  android:parentActivityName=".activities.HomeActivity"
            android:label="@string/title_activity_details"
                  android:configChanges="orientation"
                  android:screenOrientation="portrait">
            <!-- Parent activity meta-data to support 4.0 and lower -->
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".activities.HomeActivity" />
        </activity>
    </application>

</manifest>

Upvotes: 1

Views: 4898

Answers (4)

Rajeet Goyal
Rajeet Goyal

Reputation: 77

Another way to achieve this aim is - Set activity name via MainActivity.Java, Set app name via AndroidMainfest.xml

Note - Uninstall current apk from the phone and reinstall it for the app name to change


Main Activity.Java (Put this code in onCreate method)

this.setTitle(getResources().getString(R.string.activity_name));


AndroidManifest.xml (Notice android:label attribute)

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity" android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

Strings.xml

<resources>
<string name="app_name">Enter Name Here</string>
<string name="activity_name">Enter Name Here</string>

Upvotes: 2

starkshang
starkshang

Reputation: 8538

Yes, you can make these different by configuring in manifest.xml, your application name depends on this attribute android:label in application tag, like this:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:theme="@style/AppTheme"
    android:label="@string/app_name" >  <!--application name--> 

ActionBar title depends on android:label in activity tag, like this:

<activity
    android:theme="@style/AppTheme"
    android:name=".MainActivity"
    android:label="@string/activity_name" > <!--actionbar title-->

So if you set two attributes to different string, they will be different.

Consider your case, you can try this:

<activity
    android:theme="@style/AppTheme"
    android:name=".MainActivity"
    android:label="@string/activity_name" > <!--actionbar title-->
    <intent-filter android:label="@string/activity_name">
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Upvotes: 3

rd7773
rd7773

Reputation: 439

Because a single Application have multiple activities for different uses and each activity has its own actionbar which represents the header title about the activity so, is the different Application and activity title. To set the title of an activity you can call setTitle() at runtime inside activity's oncreate or anywhere you want.

For application name you can add android:label="@string/app_name" under the application tag and specify the app_name string in values. The same line (android:label="@string/Activity_name") under the activity tag in the manifest file takes the title of the actionbar of that particular activity.

Upvotes: 1

user3744881
user3744881

Reputation: 59

maybe you can alter the title in the resource file. In android studio it's located in app/res/values/strings.xml. Normally there is a string called "app_name".

Upvotes: 0

Related Questions