Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android action bar title ellipsis

I have an ellipsis in the title of action bar on my android application even though the length is well within 10-15 chars. I am using Navigation Drawer and it works fine but after a few switches it adds ellipsis to the title.

I have not used any custom xml to format my action bar. How do I remove that ellipsis ? What style/option should I use to make sure it never ellipsize the title ?

like image 754
Aakash Avatar asked Feb 20 '14 14:02

Aakash


3 Answers

Slightly different/simpler but following the same idea that worked for me:

    ...
    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            getActivity().setTitle(title);
        }
    });
    ...
like image 179
Uri Avatar answered Sep 27 '22 18:09

Uri


Simplifying Simon's answer, you can just override the setTitle method of your activities with this:

@Override
public void setTitle(final CharSequence title) {
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            MyActivity.super.setTitle(title);
        }
    });
}

I do this in a ParentActivity that is extended by all the Activities of my application.

like image 40
AlexGuti Avatar answered Sep 27 '22 16:09

AlexGuti


I have had this same problem. There is plenty of room but the TextView that holds the title text does not change size to fit its new textual content. This solves my problem:

protected Handler mUiHandler = new Handler(Looper.getMainLooper());

protected void setActionBarTitle(final CharSequence title, final boolean showHomeAsUp)
{
    mUiHandler.post(new Runnable()
    {
        @Override
        public void run()
        {
            Activity activity = getActivity();
            if(activity != null){
                ActionBar ab = activity.getActionBar();
                ab.setDisplayHomeAsUpEnabled(showHomeAsUp);
                ab.setDisplayShowTitleEnabled(false);
                activity.setTitle(title);
                ab.setDisplayShowTitleEnabled(true);
            }
        }
    });
}
like image 35
Simon Avatar answered Sep 27 '22 18:09

Simon