OutlinedBox TextInputLayout 和重心?

OutlinedBox TextInputLayout and gravity center?

如何使用 TextInputLayout 实现居中的新 OutlinedBox 样式?

当前行为:

<android.support.design.widget.TextInputLayout
    android:id="@+id/textInputLayout2"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="left"
    >
    <android.support.design.widget.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:hint="hint"
        />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:id="@+id/textInputLayout"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    >
    <android.support.design.widget.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:hint="hint2"
        />
</android.support.design.widget.TextInputLayout>

我用com.android.support:design:28.0.0.

有什么想法可以实现居中的正常外观 TextInputEditText 吗?

轮廓文本字段内的居中文本并不是我们真正支持的情况。指南中实际上根本没有提到 (https://material.io/design/components/text-fields.html)

当应用中心重力时,标签文本居中看起来确实像一个错误。修复该问题的最简单方法是向我们发送一份关于 https://github.com/material-components/material-components-android. Or you can file a bug here: https://issuetracker.google.com/issues/new?component=439535.

的修复程序

对于 Material Components Library,从版本 1.2.0-alpha02 开始,折叠标签位置通过编辑文本 gravity.

确定

使用类似的东西:

<com.google.android.material.textfield.TextInputLayout
    android:hint="@string/...."
    ...>

    <com.google.android.material.textfield.TextInputEditText
        android:gravity="center"
        ../>

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

结果是: