簡體   English   中英

Android - 如何在聚焦時以編程方式獲取TextInputLayout的提示大小?

[英]Android - How to get hint size of TextInputLayout programmatically when focused?

如何獲得輸入電子郵件ID的提示大小(在此圖中提及)?

圖片

hint文本大小與TextInputLayout 要輸入的文本相同 要在Java中獲取textSize ,請執行以下操作:

XML:

 <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="157dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="0dp"
        android:layout_marginTop="158dp">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:id="@+id/TextInputEditText"
            android:layout_height="wrap_content"
            android:hint="hint" />
    </android.support.design.widget.TextInputLayout>

MainActivity.java:

    final TextInputEditText textInputEditText = findViewById(R.id.TextInputEditText);


    textInputEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            float size = textInputEditText.getTextSize();
            Log.i("TEXT_SIZE", String.valueOf(size));
        }
    });

如果要更改textSize,可以使用textInputEditText.setTextSize();

例如:對於獲取提示大小,您需要獲取如下所示的edittext文本大小:

    EditText mEmailId= findViewById(R.id.et_email);
    mEmailId.getTextSize();

String.xml

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

然后在你的XML中寫一下

<EditText
    android:id="@+id/input_msg"
    android:inputType="text"
    android:hint="@string/edittext_hint" />

要么

減少EditText上的字體大小 - 這也將減少提示的大小。 android:textSize="15dp"

暫無
暫無

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

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