Reputation: 454
I'm making an app where, so far, the user selects a place through the Google Places API, then a new scrolling activity appears and gives details about the place. How can I change the title of the scrolling activity based on the name of the place the user chooses?
Upvotes: 4
Views: 3875
Reputation: 61
All you need to do set up toolbar_layout properties from your activity then enable Title and set the title for the toolbar:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_detail)
setSupportActionBar(toolbar)
toolbar_layout.isTitleEnabled = true
toolbar_layout.title = "My new Title"
}
Upvotes: 0
Reputation: 545
CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
toolbarLayout.setTitle("New Title.");
Upvotes: 10
Reputation: 1535
setContentView(R.layout.activity_scrolling);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("New Title");
Upvotes: 4
Reputation: 454
To change the title of an activity, use setTitle inside the activity. Ex. setTitle("myActivity);
Upvotes: 1