簡體   English   中英

如何在 Android 中的 TextInputEditText 中頂部啟動提示文本?

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

我需要 [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>

在此處輸入圖片說明

我不知道為什么你的代碼對你不起作用,它對我起作用,但你可以試試這個,我希望它起作用。

   <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"

可能是與材料設計庫相關的問題。 我檢查了不同的版本,發現相同layout不同場景。 其中下面的版本給了我你想要達到的結果。

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

輸出:

在此處輸入圖片說明

暫無
暫無

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

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