jathanasiou
jathanasiou

Reputation: 882

Android - How to properly change Actionbar title via Drawer

The default code generated when one tries to implement a navigation Drawer activity in Android Studio follows the paradigm:

    public void onSectionAttached(int number) {
    switch (number) {
        case 1:
            mTitle = ...

Is there a way for me to avoid hard-coding this? To utilize R fields and names already given to the Drawer entries ("Section 1", "Section 2" etc) so as to be picked regardless of their possible count? Ideally I would like to have this part as generic as possible and even work with different sets of Drawer entries (Navigation Drawer Fragments?).

What is the best approach for this?

Upvotes: 0

Views: 909

Answers (1)

SVG
SVG

Reputation: 123

In the onCreate method of each fragment that will be opened, you can use getActivity().getActionBar().setTitle("Whatever you want");

getSupportActionBar() in case of support libraries.

I am not clear what you want when you say generic fragments. Maybe if you can tell me something specific that is in your mind.

Upvotes: 1

Related Questions