felix
felix

Reputation: 454

How can I dynamically load the title of a Scrolling Activity based on user input?

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

Answers (4)

hardiBSalih
hardiBSalih

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

teardrop
teardrop

Reputation: 545

CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
toolbarLayout.setTitle("New Title.");

Upvotes: 10

ice spirit
ice spirit

Reputation: 1535

    setContentView(R.layout.activity_scrolling);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("New Title");

Upvotes: 4

felix
felix

Reputation: 454

To change the title of an activity, use setTitle inside the activity. Ex. setTitle("myActivity);

Upvotes: 1

Related Questions