我正在制作一个聊天应用程序,我想在 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.
}
});
关于java - 如何在editText中放置一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57689127/