<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/app_name">
</android.support.v7.widget.Toolbar>
The above is the code which is in the actitvity_main2.xml which is the child activity of activity_main.xml.
I want to change the title of this child activity when I pass from Main activity to Main2Acitivty. This is the picture which has the title of the main application(i.e. Stocks).
I want to change the title to something else when Main2Activity(this activity contains Tabbed views as you can see in the image) is loaded. I tried to use getActionBar().setTitle(<name to put on title>);
and also used setTitle(<name to put in the title>)
but nothing worked.
Please help as I am new to android.
Make Style in sytle.xml file
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Call below code from your first activity
Intent intent = new Intent(FirstActivity.this, MainActivity.class);
intent.putExtra("TitleBarName","FirstActivity");
startActivity(intent);
On SecondActivity
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String titleName = getIntent().getStringExtra("TitleBarName");
getSupportActionBar().setTitle(titleName);
and make sure to check in manifest file.
if you use toolbar then you have to put this theme in that activity in manifest file
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
</activity>
I hope this will resolve your issue.