Search code examples
androidandroid-actionbar

Why Android is truncating my ActionBar title?


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)".

Then, when you click on an item in that list, it is replacing a fragment in my Activity and it set the title to "Action".

When I come back to the first view (always in the same Activity), I reset the title to "My requests (20)", but android decide to truncate it. So the result is "My request...".

After much tests, it looks like that Android is shrinking my title when I put a smaller text in it. But it doesn't enlarge it when I put a longer text, even if there is plenty of room.

What can I do to solve this? I would like a better solution than adding spaces at the end of my short titles :)

Here is the code I use to change the title of the ActionBar :

getActivity().getActionBar().setTitle(title);   

Solution

  • I solved this problem using a custom title as described in this post.

    This is the code I use to change the title when a tab changes

    ((TextView) actionBar.getCustomView().findViewById(R.id.title)).setText(someTitle); 
    

    Note that this solution places the title to the right of the tabs in landscape mode when using actionbar tabs.