Naming my application in android

后端 未结 3 1969
我寻月下人不归
我寻月下人不归 2020-11-27 16:43

I think I\'m getting senile because I was convinced that to give a name to your application, you had to fill this part of the manifest:



        
相关标签:
3条回答
  • 2020-11-27 17:00

    The launcher actually shows android:label and android:icon for activity(ies) that declare

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    

    so application label is of no use.

    0 讨论(0)
  • 2020-11-27 17:00

    Are you referring to the title at the top of the screen when you run the application? If so, that title bar shows the label of the current activity I believe.

    0 讨论(0)
  • 2020-11-27 17:06

    It is an already known issue of the tool (I suppose you are using eclipse). Google Group - Android Developers.

    The Application and the first Activity share the same name specified in the android:label field of the <activity> item.

    If you want to use different titles for the launcher in the app list and the first activity, you can choose between these options:

    1.a) Set just the Application name in the Manifest.

    <application
            android:label="@string/app_name"
            ... >
    

    and don't specify android:label="@string/title_first_activity" for the first Activity. It will inherit the Application label.

    OR

    1.b) Set the Application name in the android:label field of the first Activity in the Manifest.

     <activity
                android:label="@string/app_name"
                ... >
                <intent-filter>
                      <action android:name="android.intent.action.MAIN" />
                      <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
     </activity>
    

    The <application> item will share the same label of the <activity> item, whether you specify a value for the <application>'s android:label field or not.

    The next step is:

    2) Set the title for the first Activity at run-time in the FirstActivity.class

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_login);
            setTitle(R.string.title_activity_login);
            //TODO: insert the rest of the code
    }
    

    In this way your first Activity will change his title few moments after it will be shown on the screen of your phone.

    0 讨论(0)
提交回复
热议问题