0

A screenshot of my activity preview

I'm new to android studio and have been following various tutorials online. Cant find the answer to this problem. if i change the app_name in the strings.xml, the name on the picture posted above also changes and if i generate the apk it also acts as the app name. I tried to add another string on the strings.xml but nothing changes. Is there a way to edit the title above without changing the final app name

strings.xml code

<resources>
<string name="app_name">Hello world</string>

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
Evance Osoo
  • 35
  • 1
  • 8
  • Possible duplicate of [How to set different label for launcher rather than activity title?](https://stackoverflow.com/questions/3488664/how-to-set-different-label-for-launcher-rather-than-activity-title) – Amit K. Saha Jul 14 '18 at 21:25

2 Answers2

1

That's because the same String is being used in both the layout where your image shows, and in your Manifest file.

You might recognize this code inside your AndroidManifest.xml file:

<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">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Note the part that says android:label="@string/app_name". That's the String that your app will show as the app name.

So if you want to use two different names, one for the app name and one for inside your layout, simply create two different Strings and assign one to the AndroidManifest.xml and the other to whichever layout you're image shows.

Jackey
  • 3,184
  • 1
  • 11
  • 12
0

Use the app_name in the intent-filter of the launcher activity. and use a different string for android:label of your activity. Manifest would look like something this -

<activity
  android:name=".MainActivity"
  android:label="@string/title_main_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>

And create <string name="title_main_activity">Hello Main Activity</string>

Amit K. Saha
  • 5,871
  • 2
  • 27
  • 35