Why Android is truncating my ActionBar title?

前端 未结 13 2071
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:11

    If anyone is still interested in a proper answer after more than 2 years I encountered this problem as well recently and realized the reason is that I updated the title from background thread. In Kotlin using supportActionBar?.title = .
    For some reason the app didn't crash as it usually does with an exception mentioning that you are touching views outside of UI thread. Instead it sets new text, but skips layout pass resulting in wrapping the text.
    So either use Activity.runOnUiThread or View.post or, when using coroutines as I did, use withContext(Dispatchers.Main) to trigger the code that updates the title.

提交回复
热议问题