- Autosizing EditText
- 5 Answers 5
- How to change the size of the EditText hint in TextInputLayout
- 2 Answers 2
- How to change the hint size of TextInputLayout
- 6 Answers 6
- Not the answer you’re looking for? Browse other questions tagged android xml hint android-textinputlayout textinputlayout or ask your own question.
- Related
- Hot Network Questions
- Subscribe to RSS
- Android EditText Hint Size
- 12 Answers 12
- Not the answer you’re looking for? Browse other questions tagged android or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- Android EditText Hint Размер
- 10 ответов
Autosizing EditText
Android recently added the support for resizing TextViews text size based on the view size and the min and max text size.
https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview.html
Unfortunately, they don’t support EditTexts, so Is there any other alternatives for EditText?
5 Answers 5
I was stuck as you, how EditText is child of TextView but don’t support autosize ¿?¿?
I have achieve this with some kind of hack. First I saw the TextView code to copy and implement as extension (in Kotlin) on EditTextView, but.. there is a bulk of methods, so endly I discard that option.
What I have do, it’s to use a TextView invisible (yes I know is a complete hack, am not very happy with that but Google should be ashamed about this)
This is my xmls
Note: It’s important both view have the same width/height
Then on my code I use the autocalculations from this textview to use on my EditTextView.
As note, for change the size of hint i use this Android EditText Hint Size.
I know it’s a hard workaround, but at least we are sure this will continue working even when resizable change on future versions, while a propetary or abandoned github lib will fail.
I hope some day, google hear us and implement on childs this wonderfull feature, and we could avoid all this stuff
Источник
How to change the size of the EditText hint in TextInputLayout
I’m trying to change the hint size in TextInputLayout , but it’s not working as desired. This is what I’d like to achieve:
This code works only for the floating label, when the EditText isn’t empty, but I want to change the hint size in the EditText itself, when it is empty.
2 Answers 2
The size of the regular hint text is set to the EditText ‘s text size when that is added to the TextInputLayout during inflation/initialization. This value is ultimately set on a private helper class in TextInputLayout , and there is no publicly exposed method or field to change it.
However, we can do a little juggling with the text sizes by subclassing TextInputLayout to intercept the adding of the EditText . When the EditText is added, we cache its text size, set the desired hint size as its text size, allow the super class to add it and initialize the hint, and finally set the EditText ‘s text size back to its original value.
To use the custom mainHintTextSize attribute, we’ll need the following in our , which we can do by just sticking the following file in the res/values/ folder, or adding to the one that’s already there.
If you don’t care to use the custom attribute, you can skip this file, and remove the TypedArray processing in the third constructor above.
This custom class is a drop-in replacement for TextInputLayout , and can be used just as it would. For example:
This approach is nice, in that it uses only publicly-accessible, documented methods, but the hint text size must be set before the EditText is added, whether that happens during inflation, or through direct instantiation.
Источник
How to change the hint size of TextInputLayout
And this is style
I don’t find something like hintSize, textSize and keyTextSize not helping
6 Answers 6
In your styles.xml
And then in your layout file:
Change the TextInputLayout’s app:errorTextAppearance in XML.
Where CustomTextInputLayoutStyle.ErrorTextStyle is defined in styles.xml as
@Santiago Martínez answer only works for hints on non empty Edittext (inside TextInputLayout )
But for empty Edittext , TextInputLayout hint takes property from Edittext textSize .
1) Add hintTextAppearance to your InputLayout with a style
2) Then just add the style to your styles.xml
For material 1.4.0
You only need to change the android:textSize attribute for the TextInputEditText for the hint size to change.
You can reduce the font size on the EditText — that will reduce the size of the hint as well. i.e. android:textSize=»16sp»
Not the answer you’re looking for? Browse other questions tagged android xml hint android-textinputlayout textinputlayout or ask your own question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.12.3.40888
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник
Android EditText Hint Size
How to reduce EditText Hint size?
12 Answers 12
You can do it by setting a size in the string recource.
then in your XML just write
This will resault in a smaller text for the hint but the original size for the input text.
Hopes this helps for future readers
You can reduce the font size on the EditText — that will reduce the size of the hint as well. i.e. android:textSize=»16sp»
I also had to do this as my hint didn’t fit in the EditText at the standard size. So I did this (in the xml set textSize to mHintTextSize):
You can set simple HTML attributes to the hint string itself.
See accepted answer here: Android EditText hint
EDIT: just played with it myself, this worked for me:
If you want to do it programmatically,
it is easy to reduce the hint size of the edittext
@marmor ‘s Approach is the best One. You can alter the number of — tags to adjust size.
You can also define the text of Hint directly as I did
Hope this will help.
define this in your strings.xml in values folder :
@user2982553 ‘s solution works great for me. You could also use AbsoluteSizeSpan , with which you can set the exact font size of the hint. Don’t use tag, ’cause the size attribute is just ignored.
I need to set a larger size for real text than hint.
You can change not only a hint’s size but also its font and style. I achieved to solve it using SpannableString and MetricAffectingSpan
1) Create a custom Hint object:
2) Create custom MetricAffectingSpan object:
3) Use:
Using onFocusChanged() listener for changing hint font size is also an option, as addTextChangeListener() won’t trigger when user clicks on text field, and blinking cursor will resize to hint font.
Also, unlike with TextChangeListener, there is no need to set initial hint font size separately.
Not the answer you’re looking for? Browse other questions tagged android or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.12.3.40888
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник
Android EditText Hint Размер
Как уменьшить размер EditText Hint?
10 ответов
Вы можете сделать это, установив размер в исходном тексте строки.
то в вашем XML просто напишите
Это приведет к отказу в меньшем тексте для подсказки, но исходный размер для ввода текста.
Надеется, что это поможет будущим читателям
Вы можете уменьшить размер шрифта на EditText , что также уменьшит размер hint . т.е. android:textSize=»16sp»
Мне также пришлось сделать это, так как мой намек не соответствовал EditText стандартного размера. Поэтому я сделал это (в xml задайте textSize для mHintTextSize):
Вы можете установить простые атрибуты HTML для самой строки подсказки.
EDIT: я просто играл с ним сам, это сработало для меня:
Если вы хотите сделать это программно,
легко уменьшить размер подсказки edittext
@user2982553 решение отлично работает для меня. Вы также можете использовать AbsoluteSizeSpan , с помощью которого вы можете установить точный размер шрифта подсказки. Не используйте тег , потому что атрибут size просто игнорируется.
@marmor Подход — лучший. Вы можете изменить количество тегов — для настройки размера.
Вы также можете определить текст подсказки напрямую, как я сделал
Надеюсь, это поможет.
Вы можете изменить не только размер подсказки, но и шрифт и стиль. Я решил решить его с помощью SpannableString и MetricAffectingSpan
1) Создайте пользовательский объект Hint :
2) Создайте собственный объект MetricAffectingSpan :
3) Использование:
Мне нужно установить больший размер для реального текста, чем подсказку.
Источник