0

I am using the default navigational drawer in Android. I want to change the title of the Action bar depending on the clicked fragment in the drawer. For this I am writing below line in my code:

getActivity().getActionBar().setTitle("Coupons");

This is returning null object. So I tried using below line of code:

getActivity().getSupportActionBar().setTitle("Coupons");

This is not able to resolve the method supportActionBar(). The activity is AppCompatActivity.

Sahil
  • 461
  • 1
  • 9
  • 24

2 Answers2

1

All the titles and strings are placed in strings.xml file in the android studio. Open strings.xml and change existing text to "Coupons".

strings.xml is placed here in the project view. Strings.xml location in Android Studio

Zia
  • 705
  • 9
  • 11
  • 1
    It solved the problem. However, I want to know how programmatically it can be solved. – Sahil Jan 31 '20 at 14:44
0

for fragment you can add below code into onCreateView() method

getActivity().setTitle("Your Title");
Mimu Saha Tishan
  • 2,402
  • 1
  • 21
  • 40