val defaultTintList =
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP && editText is AppCompatEditText) {
null //reading current value also returns null
} else {
//restoring editText.backgroundTintList (which is null) doesn't work correctly
val typedValue = TypedValue()
context.theme.resolveAttribute(R.attr.colorAccent, typedValue, true)
ColorStateList.valueOf(ContextCompat.getColor(context, typedValue.resourceId))
}
恢复:
@SuppressLint("RestrictedApi")
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP && editText is AppCompatEditText)
(editText as AppCompatEditText).supportBackgroundTintList = defaultTintList
else
editText.backgroundTintList = defaultTintList
1条答案
按热度按时间h7appiyu1#
在尝试了所有方法之后,我终于在一个C#论坛上找到了答案。将其转换为Kotlin并结合其他部分,以下是结果(在API 21和33上验证):
考虑将editText作为变量名。
备份:
恢复: