Closed. This question needs to be more focused。它当前不接受答案。
想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
在8个月前关闭。
我正在制作一个聊天应用程序,我想在editText中放置一个按钮以启用媒体文件的发送。我不知道该怎么做。
试图使editText中的矢量资产可点击,但没有成功
您可以设置
想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
在8个月前关闭。
我正在制作一个聊天应用程序,我想在editText中放置一个按钮以启用媒体文件的发送。我不知道该怎么做。
试图使editText中的矢量资产可点击,但没有成功
最佳答案
您可以使用官方的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.
}
});
10-08 17:51