简体   繁体   English

Android - 如何在聚焦时以编程方式获取TextInputLayout的提示大小?

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

How to get hint size of Enter Email Id(mentioned in this image) ? 如何获得输入电子邮件ID的提示大小(在此图中提及)?

图片

Text size of hint is same as the text to be inputed in TextInputLayout . hint文本大小与TextInputLayout 要输入的文本相同 To get textSize in Java do like below: 要在Java中获取textSize ,请执行以下操作:

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

If you want to change textSize you can use textInputEditText.setTextSize(); 如果要更改textSize,可以使用textInputEditText.setTextSize();

For example: For get hint size you need to get a edittext text size like this: 例如:对于获取提示大小,您需要获取如下所示的edittext文本大小:

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

String.xml String.xml

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

then in your XML just write 然后在你的XML中写一下

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

OR 要么

Reduce the font size on the EditText - that will reduce the size of the hint as well. 减少EditText上的字体大小 - 这也将减少提示的大小。 ie android:textSize="15dp" android:textSize="15dp"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果提示是通过编程设置的,则TextInputLayout在聚焦时不会显示提示 - TextInputLayout doesn't show hint when focused if the hint was set programmatically "以编程方式更改 TextInputLayout 聚焦和不聚焦的提示颜色" - Change TextInputLayout focused & unfocused hint color programmatically TextInputLayout:未聚焦时提示标签的颜色不同 - TextInputLayout: Different color for hint label when not focused 如何在多行中获取 Textinputlayout 提示 android? - How to get Textinputlayout hint android in multiple lines? 如何以编程方式根据特定条件更改 TextInputLayout 的焦点提示颜色(上) - How to change the focused hint color(upper) of TextInputLayout according to specific conditions programmatically 如何更改 TextInputLayout 的提示大小 - How to change the hint size of TextInputLayout 如何在Android的textinputLayout中的提示中设置* - How to set * in hint in textinputLayout in Android TextInputLayout 移动提示标签并在聚焦时更改其背景颜色 - TextInputLayout move the hint label and change it's background color when focused 如何在TextInputLayout中更改提示文本大小 - How to change hint text size in TextInputLayout 如何在TextInputLayout中更改EditText提示的大小 - How to change the size of the EditText hint in TextInputLayout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM