如何更改 TextInputLayout 中的提示文本大小
How to change hint text size in TextInputLayout
假设我想改变文字大小。我在代码中这样做,它看起来像这样:
_textInputLayout.EditText.SetTextSize(Android.Util.ComplexUnitType.Dip, 40);
当我在条目中写入文本时,它看起来像 40dip 文本。但是当条目为空时,提示文本看起来像 16-18dip。
有什么方法可以改变提示文字的大小吗?
您可以通过在字符串资源中设置大小来实现。
例如:
<string name="edittext_hint"><font size="15">Hint here!</font></string>
然后在你的XML中写
android:hint="@string/edittext_hint"
这将导致提示文本变小,但输入文本的原始大小不变。
或者像这样:
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);
}
}
});
可以通过样式更改最终提示大小/浮动标签大小,并使用类似以下内容调用 SetHintTextAppearance
:-
_nativeView.SetHintTextAppearance(App6.Droid.Resource.Style.MyTextInputLayout);
其中 MyTextInputLayout
类似于:-
<style name="MyTextInputLayout" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/blue</item>
<item name="android:textSize">44sp</item>
</style>
但是,当您开始在其中输入一些文本时,此样式的 textSize
仅适用于最终目的地。
据我所知,包括对象的属性在内,目前似乎无法更改提示的起始字体大小?
EditText
公开的地方,您可以在那里更改内容。 Hint
部分根本不由它处理,而是由 TextInputLayout
处理。似乎没有公开的对象可以访问以专门为 Hint
.
自定义此对象
假设我想改变文字大小。我在代码中这样做,它看起来像这样:
_textInputLayout.EditText.SetTextSize(Android.Util.ComplexUnitType.Dip, 40);
当我在条目中写入文本时,它看起来像 40dip 文本。但是当条目为空时,提示文本看起来像 16-18dip。
有什么方法可以改变提示文字的大小吗?
您可以通过在字符串资源中设置大小来实现。
例如:
<string name="edittext_hint"><font size="15">Hint here!</font></string>
然后在你的XML中写
android:hint="@string/edittext_hint"
这将导致提示文本变小,但输入文本的原始大小不变。
或者像这样:
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);
}
}
});
可以通过样式更改最终提示大小/浮动标签大小,并使用类似以下内容调用 SetHintTextAppearance
:-
_nativeView.SetHintTextAppearance(App6.Droid.Resource.Style.MyTextInputLayout);
其中 MyTextInputLayout
类似于:-
<style name="MyTextInputLayout" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/blue</item>
<item name="android:textSize">44sp</item>
</style>
但是,当您开始在其中输入一些文本时,此样式的 textSize
仅适用于最终目的地。
据我所知,包括对象的属性在内,目前似乎无法更改提示的起始字体大小?
EditText
公开的地方,您可以在那里更改内容。 Hint
部分根本不由它处理,而是由 TextInputLayout
处理。似乎没有公开的对象可以访问以专门为 Hint
.