I've tried several different approaches, including the one found here (which in turn led me to trying both of the top answers to this question), as well as using reflection to get access to the TextView and setting the relevant methods. Both attempts failed, the former resulting in no text at all being set to the title (and I was setting the text to the proper textview element), the latter setting the text and removing the ellipse, but not marqueeing at all. Below is my reflection attempt.
import android.content.Context;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
import android.widget.Toast;
import java.lang.reflect.Field;
public class MarqueeToolbar extends Toolbar {
public MarqueeToolbar(Context context) {
super(context);
}
public MarqueeToolbar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void setTitle(CharSequence title) {
if (!reflected) {
reflected = reflectTitle();
}
super.setTitle(title);
}
@Override
public void setTitle(int resId) {
if (!reflected) {
reflected = reflectTitle();
}
super.setTitle(resId);
}
boolean reflected = false;
private boolean reflectTitle() {
try {
Field field = Toolbar.class.getDeclaredField("mTitleTextView");
field.setAccessible(true);
TextView titleView = (TextView) field.get(this);
titleView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
titleView.setMarqueeRepeatLimit(-1);
return true;
} catch (NoSuchFieldException e) {
e.printStackTrace();
return false;
} catch (IllegalAccessException e) {
e.printStackTrace();
return false;
} catch (NullPointerException e) {
e.printStackTrace();
return false;
}
}
}