0

I have an ActionBar title like this:

String title = "This is a very looooooooooooong text.";
setTitle(title);

My ActionBar truncates the title to be:

enter image description here

How can I force ActionBar to show the complete title without truncation?

confile
  • 29,115
  • 44
  • 187
  • 340
  • this has been asked [here](http://stackoverflow.com/q/15576224/1638708), take a look at the answers – User42 Aug 27 '15 at 10:25
  • It does not provide a solution for my problem. – confile Aug 27 '15 at 10:26
  • you can use autoresize textview, but you must go with custom layout for actiobar, for autoresize textview [link](http://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds/5535672#5535672) – Rajesh Sep 01 '15 at 06:19

1 Answers1

1

You can do this by creating a custom view and set it to the action bar

myTextView layout file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:layout_centerInParent="true"
    android:text="This is a very looooooooooooong text."/>

</RelativeLayout>

And in onCreate method you just set it to the action bar:

getActionBar().setCustomView(R.layout.myTextView);
getActionBar().setDisplayShowCustomEnabled(true);

Im not sure if there is a more straightforward way, but this should work.

omar
  • 171
  • 2
  • 11