4

Suppose I want to change text size. I'm doing it in code and it looks like this:

_textInputLayout.EditText.SetTextSize(Android.Util.ComplexUnitType.Dip, 40);

When I write text in the entry it looks like 40dip text. But when entry is empty hint text looks like 16-18dip.

Is there any way to change hint text size?

Pleshkov Ivan
  • 151
  • 3
  • 8
  • I didn't try this with a `TextInputLayout`, but just a normal `EditText` and the call to `SetTextSize` was adjusting both the `Hint` size text and also the actual text when entered into the control and kept them the same size. If you can produce a small demo I will take a further look at what you have? If so my details are on my profile. – Pete Feb 05 '16 at 08:49

2 Answers2

5

Changing the final hint size / floating label size is possible via a style and calling SetHintTextAppearance using something like the following:-

_nativeView.SetHintTextAppearance(App6.Droid.Resource.Style.MyTextInputLayout);

Where MyTextInputLayout is something along the lines of:-

<style name="MyTextInputLayout" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/blue</item>
    <item name="android:textSize">44sp</item>
</style>

However the textSize from this style is only applied to the final destination, when you start to enter some text in.

From what I can see, and including the properties on the object, it doesn't appear to be possible to change the starting font size of the hint unfortunately at the moment?

Where as EditText is exposed, and you can alter things there. The Hint portion is not handled at all by it, and instead by the TextInputLayout. There appears no object exposed to get access to customize this specifically for the Hint.

Pete
  • 4,746
  • 2
  • 15
  • 21
2

You can do it by setting a size in the string recource.

For example:

<string name="edittext_hint"><font size="15">Hint here!</font></string>

then in your XML just write

android:hint="@string/edittext_hint"

This will resault in a smaller text for the hint but the original size for the input text.

Or like this:

MYEditText.addTextChangedListener(new TextWatcher(){

            @Override
            public void afterTextChanged(Editable arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1,
                    int arg2, int arg3) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onTextChanged(CharSequence arg0, int start, int before,
                    int count) {
                if (arg0.length() == 0) { 
                    // No entered text so will show hint
                    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mHintTextSize);
                } else {
                    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mRealTextSize);
                }
            }
    });
Stanojkovic
  • 1,612
  • 1
  • 17
  • 24
  • Nice, but does't work for xamarin. I saw this here http://stackoverflow.com/questions/3139676/android-edittext-hint-size and I've already tried it. – Pleshkov Ivan Feb 05 '16 at 06:24