gpt4 book ai didi

java - 如何在editText中放置一个按钮

转载 作者:行者123 更新时间:2023-12-01 19:35:40 25 4
gpt4 key购买 nike

我正在制作一个聊天应用程序,我想在 editText 中放置一个按钮以启用媒体文件的发送。我不知道该怎么办。

尝试使 editText 中的 vector 资源可点击,但没有成功

最佳答案

可以使用官方TextInputLayout组件。

您可以使用 app:endIconMode="custom" 属性自定义要使用的图标,并使用 app:endIconDrawable 指定可绘制对象.

类似于:

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/custom_end_icon"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_text"
app:endIconMode="custom"
app:endIconDrawable="@drawable/custom_icon"
app:endIconContentDescription="@string/custom_content_desc">

<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

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

您可以设置 TextInputLayout#setEndIconOnClickListener处理点击的方法。

TextInputLayout textInputLayout = findViewById(R.id.custom_end_icon);
textInputLayout.setEndIconOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
// do something.
}
});

enter image description here enter image description here

关于java - 如何在editText中放置一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57689127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com