I'm trying to marquee title in toolbar, but the marquee is not working if I build it with proguard enable.
Field f = toolbar.getClass().getDeclaredField("mTitleTextView");
f.setAccessible(true);
TextView titleTextView = (TextView) f.get(toolbar);
titleTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
titleTextView.setMarqueeRepeatLimit(-1);
titleTextView.setSelected(true);
Seem like "mTitleTextView" is obfuscated by proguard.
java.lang.NoSuchFieldException: mTitleTextView
at java.lang.Class.getDeclaredField(Class.java:631)
But it doesn't work, any idea?
You can instruct proguard not to touch private fields with following syntax:
-keepclassmembers class android.widget.Toolbar {
private android.widget.TextView mTitleTextView;
}
For the toolbar from support library:
-keepclassmembers class android.support.v7.widget.Toolbar {
private android.widget.TextView mTitleTextView;
}
See this question for more details.