Why Android is truncating my ActionBar title?

前端 未结 13 2080
Happy的楠姐
Happy的楠姐 2021-02-13 10:28

In my app, I change the title in the ActionBar from each fragment displayed. When I first start my apps, I got a list of requests, so my title is \"My requests (20)\".

T

13条回答
  •  独厮守ぢ
    2021-02-13 11:08

    In my particular case, I'm developing a hybrid app with a complex native menu structure. I'd see this issue intermittently when calling a deeplink from the hybrid content that would update the selected menu option and set the title.

    I tried several of the suggested fixes with not luck. But setting a custom view produced a strange result that gave me the feeling that I was dealing with a race condition.

    This proved true. I found that simply overriding the activity's setTitle function and wrapping the call to super in a postDelay runnable fixed this for me:

    @Override
    public void setTitle(final CharSequence title) {
        toolBar.postDelayed(new Runnable() {
            @Override
            public void run() {
                MainActivity.super.setTitle(title);
            }
        }, 200);
    }
    

    I'm using toolbar's postDelayed as a convenience method. But you can certainly use a handler here. Hope this helps.

提交回复
热议问题