本文介绍了OutlinedBox TextInputLayout和重心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 TextInputLayout 实现居中的 OutlinedBox 新样式?
How to achieve centered new OutlinedBox style with TextInputLayout?
当前行为:
<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?
Any ideas to implement centered normal looking TextInputEditText?
推荐答案
使用材料组件库,从版本1.2.0-alpha02
开始,折叠的标签位置是通过编辑文本gravity
确定的.
With the Material Components Library, starting from the version 1.2.0-alpha02
the collapsed label position is determined via the edit text 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>
结果是:
这篇关于OutlinedBox TextInputLayout和重心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!