简体   繁体   English

如何在 Android 中的 TextInputEditText 中顶部启动提示文本?

[英]How do I top start the hint text within an TextInputEditText in Android?

I need [top|start] hint text an TextInputEditText.. I use android:gravity="top|start" hint text still in center, but the text content is correct (top start)我需要 [top|start] 提示文本 TextInputEditText .. 我使用android:gravity="top|start"提示文本仍然在中心,但文本内容是正确的(顶部开始)

        <com.google.android.material.textfield.TextInputLayout
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:counterEnabled="true"
            app:counterMaxLength="200">
            <com.google.android.material.textfield.TextInputEditText
                android:text="@={textProg.textProg.text}"
                android:hint="Hint Text"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:inputType="textMultiLine"
                android:gravity="top|start"
                android:maxLength="200"
                android:textColor="@drawable/edit_text_color"/>
        </com.google.android.material.textfield.TextInputLayout>

在此处输入图片说明

i don't know why your code doesn't work with you it work with me , but you can try this i hope it work .我不知道为什么你的代码对你不起作用,它对我起作用,但你可以试试这个,我希望它起作用。

   <com.google.android.material.textfield.TextInputLayout
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="16dp"
                    app:counterEnabled="true"
                    app:counterMaxLength="200">
                <com.google.android.material.textfield.TextInputEditText
                        android:text="@={textProg.textProg.text}"
                        android:hint="Hint Text"
                        android:layout_width="match_parent"
                        android:layout_height="100dp"
                        android:inputType="textMultiLine"
                        android:ellipsize="start"
                        android:gravity="top"
                        android:maxLength="200"
                        />
            </com.google.android.material.textfield.TextInputLayout>

为什么你不尝试添加这个android:ellipsize="top|start"

Probably it's an issue related to material design library.可能是与材料设计库相关的问题。 I have checked with different version and found different scenarios for same layout .我检查了不同的版本,发现相同layout不同场景。 Among them below version gives me the result that you want to achieve.其中下面的版本给了我你想要达到的结果。

implementation 'com.google.android.material:material:1.2.0-alpha01'

Output:输出:

在此处输入图片说明

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

相关问题 如何在 Android 的 EditText 中将提示文本居中? - How do I center the hint text within an EditText in Android? TextInputEditText,如何将提示对齐到上边距 - TextInputEditText, how can align hint to the top margin Android TextInputEditText 问题提示 - Android TextInputEditText issue with hint 在 TextInputLayout 中的 TextInputEditText 顶部设置提示 - Set hint on top of TextInputEditText in TextInputLayout TextInputEditText 顶部的文本输入截断 android - TextInputEditText top of text input cut off android 如何将 drawable 左对齐与提示完美对齐,并将它们都贴近 TextInputEditText 的底部? - How do I align drawable left horizontally in a perfect line with hint and stick them both closer to the bottom in a TextInputEditText? 如何在 Android Studio 中执行浮动提示/文本? - How do I do a floating hint/text in Android Studio? 如何应用android应用程序的所有TextInputEditText的样式 - How do I apply the style of all TextInputEditText of android application Android - TextInputLayout 不包装 TextInputEditText 的提示 - Android - TextInputLayout doesn't wrap hint of TextInputEditText 如何以编程方式更改 TextInputEditText 的行和提示 colors? - How to change line and hint colors of TextInputEditText programmatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM