Action Bar Title with more than one line?

前端 未结 4 1939
清歌不尽
清歌不尽 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:40

    I found a better solution that works perfectly up to Android 4.2.2 where the icon and the title are one clickable item.

    int titleId = Resources.getSystem()
            .getIdentifier("action_bar_title", "id", "android");
    if (titleId > 0) {
        TextView title = (TextView) findViewById(titleId);
        title.setSingleLine(false);
        title.setMaxLines(2);
        title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    }
    

    If you are using ActionBarSherlock, use this code:

    int titleId = Resources.getSystem()
            .getIdentifier("action_bar_title", "id", "android");
    if (titleId == 0) {
        titleId = com.actionbarsherlock.R.id.abs__action_bar_title;
    }
    TextView title = (TextView) findViewById(titleId);
    if (title != null) {
        title.setSingleLine(false);
        title.setMaxLines(2);
        title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    }
    

提交回复
热议问题