簡體   English   中英

如何在TextInputLayout中更改提示文本大小

[英]How to change hint text size in TextInputLayout

假設我想要更改文字大小。 我在代碼中這樣做,它看起來像這樣:

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

當我在條目中寫入文本時,它看起來像40dip文本。 但是當條目為空時,提示文本看起來像16-18dip。

有沒有辦法改變提示文字大小?

可以通過樣式更改最終提示大小/浮動標簽大小,並使用以下內容調用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自定義此對象。

您可以通過在字符串recource中設置大小來實現。

例如:

<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);
                }
            }
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM