set Title for ActionBar using SpannableString - Android User Interface

Android examples for User Interface:ActionBar Title

Description

set Title for ActionBar using SpannableString

Demo Code


import android.annotation.TargetApi;
import android.app.ActionBar;
import android.os.Build;
import android.text.SpannableString;

public class Main{
    public static void setTitle(android.support.v7.app.ActionBar actionBar,
            SpannableString spannableString) {
        // BUGFIX
        // @see http://stackoverflow.com/questions/7658725/android-java-lang-illegalargumentexception-invalid-payload-item-type
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN
                && Build.MANUFACTURER.toUpperCase().equals("LGE")) {
            actionBar.setTitle(spannableString.toString());
        } else {/*from   w w  w. j av  a  2s .c o  m*/
            actionBar.setTitle(spannableString);
        }
    }
    public static void setTitle(android.support.v7.app.ActionBar actionBar,
            CharSequence charSequence) {
        actionBar.setTitle(charSequence.toString());
    }
    @TargetApi(11)
    public static void setTitle(ActionBar actionBar,
            SpannableString spannableString) {
        // BUGFIX
        // @see http://stackoverflow.com/questions/7658725/android-java-lang-illegalargumentexception-invalid-payload-item-type
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN
                && Build.MANUFACTURER.toUpperCase().equals("LGE")) {
            actionBar.setTitle(spannableString.toString());
        } else {
            actionBar.setTitle(spannableString);
        }
    }
    @TargetApi(11)
    public static void setTitle(ActionBar actionBar,
            CharSequence charSequence) {
        actionBar.setTitle(charSequence.toString());
    }
}

Related Tutorials