Action Bar Title with more than one line?

前端 未结 4 1946
清歌不尽
清歌不尽 2020-12-17 15:59

Is it possible to create the title in the Action Bar with more than one line? I need a double spaced title.

4条回答
  •  盖世英雄少女心
    2020-12-17 16:37

    The default TextView on the ActionBar does not support line wrapping, and there is no exposed method to set it to wrap. So create a flexible layout, like this: action_bar_title_layout.xml:

    
    
    
    
    
    
    

    Then set this as the custom layout on your ActionBar:

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(R.layout.action_bar_title_layout);
    ((TextView) findViewById(R.id.action_bar_title)).setText(
        "This is a long text title that will wrap to multiple lines, when necessary.");
    

提交回复
热议问题