How to change title of Activity in Android?
I am using
Window w = getWindow();
w.setTitle("My title");
to change title of my current Activity but it does not seem to work.
Can anyone guide me on how to change this?
Asked by: Blake822 | Posted: 20-01-2022
Answer 1
Try setTitle by itself, like this:
setTitle("Hello StackOverflow");
Answered by: Blake756 | Posted: 21-02-2022
Answer 2
Just an FYI, you can optionally do it from the XML.
In the AndroidManifest.xml, you can set it with
android:label="My Activity Title"
Or
android:label="@string/my_activity_label"
Example:
<activity
android:name=".Splash"
android:label="@string/splash_activity_title" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Answered by: Ryan867 | Posted: 21-02-2022
Answer 3
If you want it one time & let system handle the rest (not dynamic) then do like this in your manifest file:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name_full" > //This is my custom title name on activity. <- The question is about this one.
<intent-filter android:label="@string/app_launcher_name" > //This is my custom Icon title name (launcher name that you see in android apps/homescreen)
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Answered by: Sienna392 | Posted: 21-02-2022
Answer 4
setTitle(getResources().getText(R.string.MyTitle));
Answered by: Emma468 | Posted: 21-02-2022
Answer 5
There's a faster way, just use
YourActivity.setTitle("New Title");
You can also find it inside the onCreate() with this, for example:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.setTitle("My Title");
}
By the way, what you simply cannot do is call setTitle() in a static way without passing any Activity object.
Answered by: Charlie349 | Posted: 21-02-2022Answer 6
This worked for me.
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment, container, false);
getActivity().setTitle("My Title");
//...
}
Answered by: Tara593 | Posted: 21-02-2022
Answer 7
If you have multiple activities, you can set it like this in AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NumbersActivity"
android:label="@string/category_numbers"
android:theme="@style/category_numbers" />
<activity
android:name=".FamilyActivity"
android:label="@string/category_family"
android:theme="@style/category_family" />
<activity
android:name=".ColorsActivity"
android:label="@string/category_colors"
android:theme="@style/category_colors" />
<activity
android:name=".PhrasesActivity"
android:label="@string/category_phrases"
android:theme="@style/category_phrases" />
<activity
android:name=".ExperimentActivity"
android:label="@string/category_experiment"
android:theme="@style/category_experiment" />
</application>
Answered by: Luke606 | Posted: 21-02-2022
Answer 8
I'm using Android Studio 3.0.1.
WIth an Activity:
setTitle("Title Text");
Inside a fragment:
getActivity().setTitle("Title Text");
Answered by: Connie903 | Posted: 21-02-2022
Answer 9
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Main_Activity);
this.setTitle("Title name");
}
Answered by: Melissa746 | Posted: 21-02-2022
Answer 10
If you want to set title in Java file, then write in your activity onCreate
setTitle("Your Title");
if you want to in Manifest then write
<activity
android:name=".MainActivity"
android:label="Your Title" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Answered by: Agata233 | Posted: 21-02-2022
Answer 11
I have a Toolbar in my Activity and a Base Activity that overrides all Titles. So I had to use setTitle in onResume() in the Activity like so:
@Override
protected void onResume() {
super.onResume();
toolbar.setTitle(R.string.title);
}
Answered by: Catherine468 | Posted: 21-02-2022
Answer 12
The code helped me change the title.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_name);
ActivityName.this.setTitle("Your Activity Title");}
Answered by: Walter183 | Posted: 21-02-2022
Answer 13
Inside a MainActivity:
public class act1 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act1);
setTitle("First Activity");
}
}
Answered by: Dainton870 | Posted: 21-02-2022Answer 14
setTitle("Whatever apps"); in MainActivity.java is simplier I would say.
Answered by: Blake288 | Posted: 21-02-2022Answer 15
In Kotlin, this way:
this.title = resources.getText(R.string.fast_learning)
Answered by: Kellan706 | Posted: 21-02-2022
Answer 16
If you want to change Title of activity when you change activity by clicking on the Button. Declare the necessary variables in MainActivity:
private static final String TITLE_SIGN = "title_sign";
ImageButton mAriesButton;
Add onClickListener in onCreate() and make new intent for another activity:
mTitleButton = (ImageButton) findViewById(R.id.title_button);
mTitleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,
SignActivity.class);
String title_act = getText(R.string.simple_text).toString();
intent.putExtra("title_act", title_act);
startActivity(intent);
finish();
}
});
SecondActivity code in onCreate():
String txtTitle = getIntent().getStringExtra("title_act");
this.setTitle(txtTitle);
Answered by: Leonardo320 | Posted: 21-02-2022
Answer 17
If you're using onCreateOptionsMenu, you can also add setTitle code in onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
setTitle("Neue Aktivität");
return true;
}
Answered by: William292 | Posted: 21-02-2022
Answer 18
setTitle("Welcome Activity");
Answered by: Walter597 | Posted: 21-02-2022Similar questions
android - Change widget text in another activity
Suppose I have ActivityA and ActivityB, also suppose that ActivityA is active. I need to:
Programmatically set a text of EditText in ActivityB from ActivityA
Launch ActivityB
Here's my code:
EditText res;
final LayoutInflater factory = getLayoutInflater();
final View resultView = factory.inflate(R.layout.ActivityB, null);
// get widget
res = (EditText) resultView.findV...
android - Launch activity at certain time
I'm new to Android development, so I might be missing something obvious. I want to launch an Activity when the user's phone clock hits a specified time (similar to an alarm). However, I'm not sure how I would go about doing this as constant polling of the clock seems inefficient and a waste of resources. Do I need to capture broadcast events from the clock, or use PendingIntents? If someone could ...
android - How to to make 2 MapView on one Activity?
Is it possible to make 2 MapView on one Activity ?
If so, How to make it ?
I've tried but no luck.
Thanks in advance.
android - Need advice in how to update my Activity due to contact info changes
I have an activity which queries and display some Contact Information. It has a button which launches the intent for 'Edit Contact' (the default Android activity).
What should I do to refresh my view in case user edits Contact Information?
re-query in the onResume() of my activity?
add a content observer?
android - Replace current activity
I need to replace the current activity with a new one. That is, I want to start a new activity and remove the current activity from the task stack.
Based on the documentation, it seems the best way would be to start the activity using Activity.startActivity as per usual, and then cal...
android - How to enforce activity if app is running?
I start an Activity from my Widget, which should start a special view.
But if the app is already running (not left with back button), Android instead activates the activity that was last shown.
Is there any flag or other way to avoid this behaviour?
Closing the previous activity wouldn't be a problem in my app, there's no user input that would be lost.
I tried a workaround with finish() in onStop(), but onS...
How can android find a certain activity or service based on a given Intent?
Suppose that I installed app A and app B, app A has a main activity, and app B wants to show that activity by sending a intent. My question is that how android knows I have installed app A and is able to map the intent to its activity? Is there any windows-registry-like store saving such information?
Thank You
Android - Make sure activity is alive before firing Intent?
I am currently firing an Intent to a Broadcast Receiver which in turns starts an Activity.
Then from the same Service another Intent is fired to a Broadcast Receiver thats in the Activity.
The problem is that the Activity isn't getting the Intent meant for it because it is fired before it is alive and the Broadcast Reciever is registered.
I was wondering is there anyway to make sure an Activity is a...
java - How do I send some data (eg. a String) from my Activity to a Service ...in Android?
Usually, I putExtra inside an Intent to transfer stuff between Activities.
But it seems like I can't do this with a Service?
Bundle extras = getIntent().getExtras();
That doesn't work for a android Service. How do I send a string from an Activity to a Service then?
android - Save activity gui state
So I'm writing an app. I would like to be able to press the home key to leave the app, do something else for a moment, then come back to the app by picking it from the launcher. I want the app to have exactly the same state as it did when I left it.
To this end, I have implimented onSaveInstanceState() to create a bundle, and I use this bundle in onCreate() (checking if it is null, of course).
This is what I would ...
Should only 1 view go in 1 Activity, in Android?
android - Launch activity at certain time
I'm new to Android development, so I might be missing something obvious. I want to launch an Activity when the user's phone clock hits a specified time (similar to an alarm). However, I'm not sure how I would go about doing this as constant polling of the clock seems inefficient and a waste of resources. Do I need to capture broadcast events from the clock, or use PendingIntents? If someone could ...
android - How to to make 2 MapView on one Activity?
Is it possible to make 2 MapView on one Activity ?
If so, How to make it ?
I've tried but no luck.
Thanks in advance.
android - Need advice in how to update my Activity due to contact info changes
I have an activity which queries and display some Contact Information. It has a button which launches the intent for 'Edit Contact' (the default Android activity).
What should I do to refresh my view in case user edits Contact Information?
re-query in the onResume() of my activity?
add a content observer?
eclipse - how to add image buttons in each Android activity?
can any one guide me how to add some menu related buttons at the bottom of each activity?
android - Replace current activity
I need to replace the current activity with a new one. That is, I want to start a new activity and remove the current activity from the task stack.
Based on the documentation, it seems the best way would be to start the activity using Activity.startActivity as per usual, and then cal...
android - How to enforce activity if app is running?
I start an Activity from my Widget, which should start a special view.
But if the app is already running (not left with back button), Android instead activates the activity that was last shown.
Is there any flag or other way to avoid this behaviour?
Closing the previous activity wouldn't be a problem in my app, there's no user input that would be lost.
I tried a workaround with finish() in onStop(), but onS...
eclipse - How to display custom list activity in Android?
I want to display data in list activity. How do I achieve this?
TITLE Date
Sub Title Button
TITLE Date
Sub Title Button
TITLE Date
Sub Title Button
.
.
.
.
and so on
Does a tutorial exist related to custom list activity?
android dialog activity position
I created an non-maximized activity using android:theme="@android:style/Theme.Dialog" to make it looks like a dialog. I need to change the position of the activity on screen but I didn't find how to do this...
How can android find a certain activity or service based on a given Intent?
Suppose that I installed app A and app B, app A has a main activity, and app B wants to show that activity by sending a intent. My question is that how android knows I have installed app A and is able to map the intent to its activity? Is there any windows-registry-like store saving such information?
Thank You
Android - Make sure activity is alive before firing Intent?
I am currently firing an Intent to a Broadcast Receiver which in turns starts an Activity.
Then from the same Service another Intent is fired to a Broadcast Receiver thats in the Activity.
The problem is that the Activity isn't getting the Intent meant for it because it is fired before it is alive and the Broadcast Reciever is registered.
I was wondering is there anyway to make sure an Activity is a...
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android