androidandroid-titlebarcustom-titlebar

set title bar name of a activity


I'm trying to change my applications activity menu bar title. I managed to change font as follows. Anyone help me to change the name of the title. It may be just a one line, but I can't figure it out.

int actionBarTitle = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    TextView actionBarTitleView = (TextView) getWindow().findViewById(actionBarTitle);
    if(actionBarTitleView != null){
        actionBarTitleView.setTypeface(typeFace);
    }

Solution

  • Not sure you can do it your way or not but you can use the bellow solution:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.your_activity);
    
        final ActionBar actionBar = getActionBar();
    
        // actionBar
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    
        // titleTextView
        TextView titleTextView = new TextView(actionBar.getThemedContext());
    
        titleTextView.setText("Title");
        titleTextView.setTypeface( your_typeface);
    
        titleTextView.setOtherProperties();
    
        // Add titleTextView into ActionBar
        actionBar.setCustomView(titleTextView);
    
    }
    

    By doing this solution, you have FULL control of your textview title.