繁体   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