I tried several different approaches, including the one found here (which in turn prompted me to try both of the top answers to this question), and also use reflection to access the TextView and set the appropriate methods. Both attempts failed, the first of which did not result in the text being assigned no title at all (and I set the text to the corresponding textview element), the last set the text and deleted the ellipse, but did not divide it at all. Below is my attempt at reflection.
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;
}
}
}