如何在editText中放置按钮 [英] how to put a button in an editText
问题描述
我正在制作一个聊天应用程序,我想在editText中放置一个按钮以启用媒体文件的发送.我不知道该怎么办.
I am making a chat application and I wanted to put a button in an editText to enable the sending of Media files. I don't know how to go about it.
试图使editText中的矢量资产可点击,但没有用
Tried to make the vector asset in the editText clickable but it is not going
推荐答案
You can use the official TextInputLayout
component.
您可以使用 app:endIconMode="custom"
属性自定义要使用的图标,并通过 app:endIconDrawable
指定可绘制对象.
You can customize the icon to use using the app:endIconMode="custom"
attribute and specifying the drawable with 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
方法来处理点击.
You can set the TextInputLayout#setEndIconOnClickListener
method to handle the click.
TextInputLayout textInputLayout = findViewById(R.id.custom_end_icon);
textInputLayout.setEndIconOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
// do something.
}
});
这篇关于如何在editText中放置按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!