在某些机型上lineSpacing 初始化正常。 编辑时lineSpacing 设置直接消失。
stackoverflow 上查了发现。 此为系统BUG。 只有在5.0以上某些机型出现。
解决方案
/**
* Created by 4399-1500 on 2017/3/22.
*/
public class AutoLineEditText extends EditText {
public AutoLineEditText(Context context) {
super(context);
}
public AutoLineEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AutoLineEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
if (lengthBefore != lengthAfter) {
int startSelection = getSelectionStart();
setText(text);
setSelection(startSelection);
}
}
}