はじめに
仕事で数十分悩んだので記事にしておきます。端末のアプリアイコンが並ぶ画面でアイコン下のアプリ名を変えたくて調べると、strings.xmlの"app_name"の値がアプリ名なのでそこを変えようといった内容がヒットします。しかし自分の環境では"app_name"の値を変えても反映されず、さらに調べてみると自分の認識が間違っていたことに気づきました。
原因
人によっては"app_name"の値を変更することで解決ができるのですが、それはおそらくAndroidManifest.xmlでメインに設定しているactivityのandroid:labelに"@string/app_name"が設定されているからです。今回の場合、アイコン下のアプリ名はapplicationのandroid:labelに設定されている値であると誤解しており、メインに設定しているactivityのandroid:labelに"@string/app_name"が設定されておらず、それに気づかずに"app_name"の値を変更していました。
まとめると仕様としては
アイコン下のアプリ名には、メインに設定しているactivityのandroid:labelの値が表示されます。メインに設定しているactivityのandroid:labelの値が未設定の場合は、applicationのandroid:labelの値が表示されます。
例えば以下のAndroidManifest.xmlだと、メインに設定しているactivityのandroid:labelに"MainActivity"と設定されているので、アイコン下のアプリ名には"MainActivity"と表示されます。
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" > <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.Sample" tools:targetApi="31" > <activity android:name=".MainActivity" android:exported="true" android:label="MainActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SubActivity" android:exported="true" android:label="SubActivity" > </activity> </application> </manifest>
以下の記事がわかりやすいので合わせてご確認ください。