Android app icon name picked from activity label than from application label

て烟熏妆下的殇ゞ 提交于 2020-05-11 04:16:50

问题


Not sure if anyone else posted this question, didn't find any, though there are similar ones.

This is my manifest xml:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
      android:name="com.listCalc.tutorial.simpleinappbillingv3.ui.StartUpActivity"
      android:label="@string/activity_startup_label"
      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="com.listCalc.tutorial.simpleinappbillingv3.ui.MainActivity"
      android:label="@string/activity_main_label"
      android:screenOrientation="portrait" />
    <activity
      android:name="com.listCalc.tutorial.simpleinappbillingv3.ui.PurchasePassportActivity"
      android:label="@string/activity_purchase_label"
      android:screenOrientation="portrait" />
  </application>

String.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

  <string name="app_name">List Calc in-app billing V3</string>
  <string name="hello_world">Hello world!</string>
  <string name="menu_settings">Settings</string>
  <string name="main_button_purchase_passport_text">Purchase Passport</string>
  <string name="main_cont_desc_image_passport">purchased passport</string>
  <string name="activity_startup_label">Loading</string>
  <string name="activity_main_label">Main Menu</string>
  <string name="activity_purchase_label">Making Purchase</string>

</resources>

The application name i.e. the launcher icon name is being picked up as "activity_startup_label" and not "app_name"

What am I doing wrong?


回答1:


What am I doing wrong?

Nothing. This is working as designed.

You are welcome to also have an android:label attribute on the <intent-filter>, which should be used for the launcher icon label, according to the documentation:

The icon and label set for an intent filter are used to represent a component whenever the component is presented to the user as fulfilling the function advertised by the filter. For example, a filter with "android.intent.action.MAIN" and "android.intent.category.LAUNCHER" settings advertises an activity as one that initiates an application — that is, as one that should be displayed in the application launcher. The icon and label set in the filter are therefore the ones displayed in the launcher.




回答2:


If you have a "launcher activity" with [label name] & "application tag" also with a different [label name] then Android will take the [label name] from the Launcher Activity.




回答3:


An alternative solution to the one proposed by Commonsware (which I've found to be hit and miss on some devices) is to set the label of the application in the manifest as you're doing, to not set the label of the launcher activity in the manifest and instead to set it programmatically in your activity's onCreate(Bundle) method as follows:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.activity_startup_label);
    // do whatever else you need to
}



回答4:


Probably because the label of the main activity is "activity_startup_label"




回答5:


In your manifest.xml change your label to:

    android:label="@string/app_name"


来源:https://stackoverflow.com/questions/21459785/android-app-icon-name-picked-from-activity-label-than-from-application-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!