您的位置:首页 > 移动开发 > Android开发

Android Editview lineSpacingExtra (行间距) 失效问题。

2017-03-23 17:46 836 查看
 在某些机型上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);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android