android - 如何在多行 TextInputLayout 中将 EndIconDrawable 移动到 End|Bottom

标签 android material-design android-textinputlayout

我正在尝试将 EndIconDrawable 添加到具有重力结束 | 底部的多行 TextInputLayout。 EndIconDrawable 的默认位置是 end|center。
现在我的问题是:这是否可以使用 Material 元素的默认设置,或者我是否必须将其实现为 CustomElement。

这是我目前对该元素的来源:

    <com.google.android.material.textfield.TextInputLayout
        style="@style/Theme.MyApp.BoxedLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:hint="Outlinebox"
        app:endIconCheckable="true"
        app:endIconDrawable="@drawable/ic_mic_black_24dp"
        app:endIconMode="custom">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="top"
            android:maxLines="5"
            android:minLines="5"
            android:textColor="@color/blue_grey_900" />

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

这是样式部分:

    <style name="Theme.MyApp.BoxedLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
        <item name="boxStrokeColor">@color/blue_grey_900</item>
        <item name="boxStrokeWidth">2dp</item>
    </style>

这张图片显示了结果应该是这样的:
TextInputLayout with multiline and EndIcon on BottomEnd (edited)

最佳答案

我遇到了同样的问题,发现结束图标是一个 CheckableImageButton,ID 为 com.google.android.material.R.id.text_input_end_icon 放置在 FrameLayout 中。因此,只需根据需要自定义 FrameLayout.Params。
enter image description here
检查以下代码 fragment :

// using viewbinding
       private ActivityCommentBinding mBinding;

// change the end icon gravity
       FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mBinding.commentTextLayout
                .findViewById(com.google.android.material.R.id.text_input_end_icon)
                .getLayoutParams();
        params.gravity = Gravity.BOTTOM;
        mBinding.commentTextLayout
                .findViewById(com.google.android.material.R.id.text_input_end_icon)
                        .setLayoutParams(params);
运行时结果:
enter image description here
我还打开了一个 GitHub 功能请求 here.

关于android - 如何在多行 TextInputLayout 中将 EndIconDrawable 移动到 End|Bottom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60416584/

相关文章:

android - 如何将 Material Components 库中的芯片添加到 android 中的输入字段?

css - 如何在窗口调整大小时更改 Bootstrap 网格?

android - android TextInputLayout 中的表单验证无法正常工作

android - 在 TextInputLayout 中同时启用 errorEnabled 和 passwordToggleEnabled

android - 库不可导入

android - TextInputLayout - 在静止状态下更改 EditText 中的 float 标签提示颜色

android - 手机不想从 Android 浏览器拍照

Android:如何让服务器知道用户仍然在线?

android - NestedScrollView 内的 NestedScrollView 不滚动

android - 背景有问题 :@drawable/img