【问题标题】:TextInputLayout Hint gravity bottomTextInputLayout 提示重力底部
【发布时间】:2020-11-02 19:35:23
【问题描述】:

提示始终垂直居中,我希望它与靠近边框的视图底部对齐,并带有一点填充。我设法为TextInputEditText 的文本做到了,但我不能为提示做到这一点。

它是这样的

这是我的布局 XML:

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/first_name_layout"
            style="@style/My.TextInputLayout.FilledBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/first_name"
            app:layout_constraintTop_toTopOf="parent">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/first_name_edit_text"
                style="@style/TextInputEditTextForm"
                android:inputType="textPersonName" />
        </com.google.android.material.textfield.TextInputLayout>

还有我的styles.xml

<style name="My.TextInputLayout.FilledBox" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
    <item name="materialThemeOverlay">@style/MyThemeOverlayFilledPadding</item>
    <item name="android:gravity">bottom</item>
    <item name="android:textColorHint">@color/gray</item>
    <item name="boxBackgroundColor">@android:color/transparent</item>
    <item name="boxStrokeColor">@color/grey_little</item>
    <item name="boxStrokeWidth">0.5dp</item>
    <item name="hintTextAppearance">@style/FormInputLabel</item>
    <item name="hintTextColor">@color/gray</item>
</style>

<style name="MyThemeOverlayFilledPadding">
    <item name="colorControlActivated">@color/gray_light</item>
    <item name="editTextStyle">@style/MyTextInputEditText_filledBox_padding</item>
</style>

<style name="MyTextInputEditText_filledBox_padding" parent="@style/Widget.MaterialComponents.TextInputEditText.FilledBox">
    <item name="android:paddingBottom">5dp</item>
</style>

<style name="TextInputEditTextForm" >
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:gravity">bottom</item>
    <item name="android:lines">1</item>
    <item name="android:textColor">@color/gray_x_dark</item>
    <item name="android:textSize">@dimen/text_xx_small</item>
</style>

<style name="MyThemeOverlayFilledPaddingHint">
    <item name="android:paddingBottom">5dp</item>
    <item name="android:gravity">bottom</item>
</style>

<style name="FormInputLabel" parent="TextAppearance.Design.Hint">
    <item name="android:textSize">@dimen/text_xxxx_small</item>
    <item name="materialThemeOverlay">@style/MyThemeOverlayFilledPaddingHint</item>
    <item name="android:gravity">bottom</item>
</style>

【问题讨论】:

    标签: android material-design


    【解决方案1】:

    提示由辅助类 CollapsingTextHelper 绘制,该类在私有包范围内可用。 您可以通过反射访问该字段,但访问私有字段仅在 Pre Orea 设备上可用

    【讨论】:

    • 我还需要定位较新的版本
    • 即使使用反射和“setExpandedTextGravity”,它也不能在旧版本和新版本的操作系统上运行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    • 1970-01-01
    • 2017-01-13
    • 2015-08-15
    • 2018-10-06
    相关资源
    最近更新 更多