I have an edittext that acts weird when I set a hint to it.
XML :
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="5dip"
android:layout_marginTop="8dip"
android:background="@android:drawable/edit_text"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingRight="0dip" >
<EditText
android:id="@+id/pinDisplay"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.85"
android:background="@null"
/>
<ImageButton
android:id="@+id/backspace"
style="@android:style/Widget.Button"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_marginBottom="2dip"
android:layout_marginRight="8dip"
android:layout_marginTop="2dip"
android:layout_weight="0.15"
android:gravity="center"
android:src="@android:drawable/ic_input_delete" />
</LinearLayout>
Code :
private float hintTextSize = 24;
private void initializeInputText() {
input = (EditText) findViewById(R.id.pinDisplay);
input.setInputType(InputType.TYPE_NULL);
input.setTransformationMethod(PasswordTransformationMethod.getInstance());
input.setTextSize(TypedValue.COMPLEX_UNIT_SP, hintTextSize);
input.setHint("Kies pincode");
input.setCursorVisible(false);
input.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
return true;
}
});
input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLengthInput) });
input.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before,
int count) {
input.setError(null);
if (s.length() >= maxLengthInput) {
input.setCursorVisible(false);
btnOk.setEnabled(true);
btnOk.setTextColor(Color.parseColor("#00B32D")); //Green
} else {
btnOk.setEnabled(false);
btnOk.setTextColor(Color.parseColor("#B8B8B8")); //Light gray
input.setCursorVisible(true);
input.setSelection(input.getText().length());
}
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
if (!input.getText().toString().equals("")) {
input.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
} else {
input.setTextSize(TypedValue.COMPLEX_UNIT_SP, hintTextSize);
}
}
});
}
This is the first:
But when I add a number the edittext grows and takes a lot more space.
What can be the cause ?