How to change android Activity label

2019-03-17 07:09发布

I have created an Activity and declared in Manifest file. But I would like to re-use the same Activity for other purpose.

 <activity
            android:configChanges="orientation|keyboardHidden"
            android:label="Main Menu"
            android:name=".MainMenu"
            android:theme="@android:style/Theme.Light" >
        </activity>

I need to change the Label dynamically. Thanks in Advance

9条回答
Animai°情兽
2楼-- · 2019-03-17 07:48

In your Manifest file

Initially, your code was like this.

    <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".NumbersActivity"  />
    <activity android:name=".FamilyMembersActivity"  />
    <activity android:name=".ColorsActivity"  />
    <activity android:name=".PhrasesActivity" />
    </activity>
</application>

But after changes to add Labels.

<activity android:name=".NumbersActivity" android:label="Numbers" />
    <activity android:name=".FamilyMembersActivity" android:label="Family Members" />
    <activity android:name=".ColorsActivity" android:label="Colors" />
    <activity android:name=".PhrasesActivity" android:label="Phrases" >
    </activity>
</application>

is the optimum way to change the Label name.

courtesy.(ryanwaite28)

查看更多
混吃等死
3楼-- · 2019-03-17 07:50

android:label="any word you want"/>

查看更多
趁早两清
4楼-- · 2019-03-17 07:53
public class YourActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
      setTitle(R.string.your_title);
      setContentView(R.layout.main);
  }
}
查看更多
不美不萌又怎样
5楼-- · 2019-03-17 07:59

You can define the string in res/string.xml file and then add android:label to the AndroidMenifest.xml file

string.xml code
<string name="string_name">text to display</string>

AndroidMenifest.xml code

<activity android:name=".SomeActivity"
            android:label="@string/string_name"/>
查看更多
爱情/是我丢掉的垃圾
6楼-- · 2019-03-17 08:00

Use

setTitle(int titleId)

or

setTitle(CharSequence title)

查看更多
Explosion°爆炸
7楼-- · 2019-03-17 08:02

Static, not Dynamic

Go to your AndroidManifest.xml file and add the android:label attribute to the activity tag you want, like this:

<activity android:name=".name" android:label="label"/>
查看更多
登录 后发表回答