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);
First, add a font file in the src/main/assets/fonts/ of your project. Then create variables for Toolbar and text title and call the method findViewById(). Create a new Typeface from the specified font data. And at last setTypeface in text title.
actionBarSize will resolve to 0 size on pre-3.0 devices. So when using ActionBarCompat one would stick to android.
I know this question was posted a long time ago, but I recently ran into this issue and it caused a hell of a headache. I'm working on a Galaxy Note 10.1 and my title was "BidItems" and I only had the action overflow item visible, yet sometimes, "BidItems" became "BidIt..." which is just ridiculous. After much testing, I found that the reason for this truncating behavior in my application is that I was calling a method using ((MyActivity) getApplication()).setTitle();
method from one of my fragments. The setTitle()
method in my Activity calls getActionBar().setTitle()
. As soon as I called this method, my title was truncated for no reason. But simply calling setTitle()
from my activity worked just fine.
I really hope this saves people the headache it caused me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With