Android toolbar center title and custom font

前端 未结 30 3137
时光说笑
时光说笑 2020-11-22 04:11

I\'m trying to figure out the right way to use a custom font for the toolbar title, and center it in the toolbar (client requirement).

At the moment, i\'m using the

30条回答
  •  借酒劲吻你
    2020-11-22 04:52

    we don't have direct access to the ToolBar title TextView so we use reflection to access it.

      private TextView getActionBarTextView() {
        TextView titleTextView = null;
    
        try {
            Field f = mToolBar.getClass().getDeclaredField("mTitleTextView");
            f.setAccessible(true);
            titleTextView = (TextView) f.get(mToolBar);
        } catch (NoSuchFieldException e) {
        } catch (IllegalAccessException e) {
        }
        return titleTextView;
    }
    

提交回复
热议问题