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?
CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
toolbarLayout.setTitle("New Title.");
setContentView(R.layout.activity_scrolling);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("New Title");
To change the title of an activity, use setTitle inside the activity. Ex. setTitle("myActivity);
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"
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.