Last active
August 29, 2015 14:25
-
-
Save AKiniyalocts/fee90c201212afa038b8 to your computer and use it in GitHub Desktop.
This fixes the InputTextLayout in the Android Design Library not showing hint text correctly on 5.0+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** | |
* Depends on android design library. | |
* | |
*/ | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.support.design.widget.TextInputLayout; | |
import android.support.v4.view.ViewCompat; | |
import android.util.AttributeSet; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.EditText; | |
public class CustomTextInputLayout extends TextInputLayout { | |
private boolean mIsHintSet; | |
private CharSequence mHint; | |
public CustomTextInputLayout(Context context) { | |
super(context); | |
} | |
public CustomTextInputLayout(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
@Override | |
public void addView(View child, int index, ViewGroup.LayoutParams params) { | |
if (child instanceof EditText) { | |
mHint = ((EditText)child).getHint(); | |
} | |
super.addView(child, index, params); | |
} | |
@Override | |
protected void onDraw(Canvas canvas) { | |
super.onDraw(canvas); | |
if (!mIsHintSet && ViewCompat.isLaidOut(this)) { | |
setHint(null); | |
CharSequence currentEditTextHint = getEditText().getHint(); | |
if (currentEditTextHint != null && currentEditTextHint.length() > 0) { | |
mHint = currentEditTextHint; | |
} | |
setHint(mHint); | |
mIsHintSet = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment