Android:如何默认显示TextInputLayout的suffixText?

标签 android android-layout material-design android-textinputlayout android-textinputedittext

我正在使用最新版本的 android Material 设计库 (1.2.0-alpha05)。我在 TextInputLayout 中添加了 app:suffixText="PlaceHolder"。我希望默认显示 suffixText,但目前,它仅在 TextInputLayout 获得焦点时可见。 当 TextInputLayout 失去焦点时,我看不到 suffixText。这是我的代码-:

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:suffixText="PlaceHolder"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:hint="hint">

         <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent"
android:layout_height="wrap_content" />

</com.google.android.material.textfield.TextInputLayout>

When I am launching the Activity, I can't see suffix text of TextInputLayout

Only after clicking on TextInputEditText, I can see suffix text

请告诉我,如何默认显示后缀文本。

最佳答案

您也可以使用 app:expandedHintEnabled="false" 在文本字段为空时显示后缀/前缀。

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:suffixText="...."
            app:expandedHintEnabled="false"
            >

            <com.google.android.material.textfield.TextInputEditText
                .../>

        </com.google.android.material.textfield.TextInputLayout>

enter image description here

关于Android:如何默认显示TextInputLayout的suffixText?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60880048/

相关文章:

android - 以编程方式设置 LinearLayout 子项的权重

android - BottomNavigationView 文本调整大小动画问题基于所使用的主题

c# - MVVM light - 导航服务android

Android Intent 过滤器问题

android - 出于性能目的,在 AppCompat 1.4.0 及更高版本的 textview 中禁用 emoji2

reactjs - Material UI Chip数组如何像Angular Chip Input一样使用?

javascript - 为什么 md-select 没有填充 Angular ?

java - 如何在Activity和其他Activity创建的线程之间进行通信

java - setContentView 可以获取 xml 布局以外的输入吗?

java - 在创建 fragment 时使用 ConstraintLayout