TextInputLayout.java 文件源码

java
阅读 34 收藏 0 点赞 0 评论 0

项目:permissionsModule 作者:
private void ensureBackgroundDrawableStateWorkaround() {
    final Drawable bg = mEditText.getBackground();
    if (bg == null) {
        return;
    }

    if (!mHasReconstructedEditTextBackground) {
        // This is gross. There is an issue in the platform which affects container Drawables
        // where the first drawable retrieved from resources will propogate 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
            mHasReconstructedEditTextBackground =
                    DrawableUtils.setContainerConstantState(
                            (DrawableContainer) bg, newBg.getConstantState());
        }

        if (!mHasReconstructedEditTextBackground) {
            // 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.
            mEditText.setBackgroundDrawable(newBg);
            mHasReconstructedEditTextBackground = true;
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号