Michael
Michael

Reputation: 33297

Force ActionBar to show the complete title without truncation?

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?

Upvotes: 0

Views: 534

Answers (1)

omar
omar

Reputation: 291

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.

Upvotes: 1

Related Questions