private void ensureBackgroundDrawableStateWorkaround() {
final int sdk = Build.VERSION.SDK_INT;
if (sdk != 21 && sdk != 22) {
// The workaround is only required on API 21-22
return;
}
final Drawable bg = editText.getBackground();
if (bg == null) {
return;
}
if (!hasReconstructedEditTextBackground) {
// This is gross. There is an issue in the platform which affects container Drawables
// where the first drawable retrieved from resources will propagate any changes
// (like color filter) to all instances from the cache. We'll try to workaround it...
final Drawable newBg = bg.getConstantState().newDrawable();
if (bg instanceof DrawableContainer) {
// If we have a Drawable container, we can try and set it's constant state via
// reflection from the new Drawable
hasReconstructedEditTextBackground =
DrawableUtils.setContainerConstantState(
(DrawableContainer) bg, newBg.getConstantState());
}
if (!hasReconstructedEditTextBackground) {
// If we reach here then we just need to set a brand new instance of the Drawable
// as the background. This has the unfortunate side-effect of wiping out any
// user set padding, but I'd hope that use of custom padding on an EditText
// is limited.
ViewCompat.setBackground(editText, newBg);
hasReconstructedEditTextBackground = true;
}
}
}
BufferTextInputLayout.java 文件源码
java
阅读 32
收藏 0
点赞 0
评论 0
项目:BufferTextInputLayout
作者:
评论列表
文章目录