I tried to set a title for an ActionBar
with the following code:
@Override
public void onResume() {
((MainActivity) getActivity()).getSupportActionBar().setTitle(getResources().getString(R.string.artist));
super.onResume();
}
but Android Studio shows me this warning:
I searched on StackOverflow that it will be fixed by adding this code if(getSupportActionBar()!=null)
in front of my code. But it causes an error in my script.
I'm not sure how to fix this.