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条回答
Rolldiameter
2楼-- · 2019-03-17 08:04
if(Condition)
{
    setTitle("Your Title");
}
else
{
    // your Default Title from Manifest
}

Try to use this line.

查看更多
forever°为你锁心
3楼-- · 2019-03-17 08:05

I have the same problem, Try this in onCreate it's work for me!

public class YourActivityName extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    setTitle("Your Title");
  }
}
查看更多
混吃等死
4楼-- · 2019-03-17 08:07

You need to use setTitle for this:

setTitle(R.string.your_title);
//or
setTitle("new title");
查看更多
登录 后发表回答