I'm making a custom action bar layout, and I want to reuse it in all activities. For that I want to be able to set the title in the action bar layout to the activity title,
View actionBarView =LayoutInflater.from(senderActivity.getApplicationContext()).inflate(R.layout.az_actionbar, null);
((TextView)actionBarView.findViewById(R.id.azActionBar_tv_title)).setText("tetetete");
But the TextView doesn't change its text (doesn't show "tetetetete")
Any ideas why is this happening? or is there a better way to apply the custom ActionBar layout globally?
The method I used to customize the actionbar.
Java code of the helper method that is being called on onCreate from each activity with Helper.setAzCustomActionBar(this)
:
public static void setAzCustomActionBar(AppCompatActivity sender){
//getting the activity title
String title;
try {
ActivityInfo activityInfo = sender.getPackageManager().getActivityInfo(
sender.getComponentName(), PackageManager.GET_META_DATA);
title = activityInfo.loadLabel(sender.getPackageManager())
.toString();
} catch (PackageManager.NameNotFoundException e) {
title = "abcd";
}
View actionBarView = LayoutInflater.from(sender.getApplicationContext()).inflate(R.layout.az_actionbar, null);
//This is the line that doesn't work
((TextView) actionBarView.findViewById(R.id.azActionBar_tv_title)).setText(title);
sender.getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
sender.getSupportActionBar().setCustomView(R.layout.az_actionbar);
}