我正在尝试将 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。
检查以下代码 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);
运行时结果:我还打开了一个 GitHub 功能请求 here.
关于android - 如何在多行 TextInputLayout 中将 EndIconDrawable 移动到 End|Bottom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60416584/