Can i change title of my toolbar in my constructor if yes then how can it possible?
public DashboardFragment() {
((AppCompatActivity) this.getActivity()).getSupportActionBar().setTitle("DashBoard");
}
Can i change title of my toolbar in my constructor if yes then how can it possible?
public DashboardFragment() {
((AppCompatActivity) this.getActivity()).getSupportActionBar().setTitle("DashBoard");
}
Assuming you have a Toolbar defined in your Activity's xml, you can access it from a Fragment using the following method:
Override the onAttach()
method in your Fragment to get a reference to the parent Activity once it is available. Then, simply get your reference to the Toolbar (that should be defined in your Activity xml) and simply set the title. Like this...
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
toolbar.setTitle("Your Custom Title");
}