Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change android Activity label

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

like image 859
noname Avatar asked Apr 13 '12 09:04

noname


People also ask

How do I change the activity label?

To change the title of an activity (to show a more custom title for a certain activity than the application title), you can set the new title either through calling setTitle("foo") on the activity or by setting android:label="@string/price_after_rebate" in your activity style.

How do you change labels on Android?

Go to the app > manifests > AndroidManifest. xml file and change the android:label field in your application node in AndroidManifest.

How do I change my MainActivity name on Android?

Yes, you can change the name of MainActivity by, opening the directory of the java file in android studio, right-click on it and find refactor, then rename, put in the name you like then click on refactor.


2 Answers

Use

setTitle(int titleId) 

or

setTitle(CharSequence title) 
like image 129
Shubhayu Avatar answered Oct 07 '22 01:10

Shubhayu


public class YourActivity extends Activity {   @Override   public void onCreate(Bundle savedInstanceState) {       setTitle(R.string.your_title);       setContentView(R.layout.main);   } } 
like image 32
SamSPICA Avatar answered Oct 07 '22 02:10

SamSPICA