Android 如何从多媒体资料中获取图像或从相机中获取图像并将其插入编辑文本?
我是Android编程新手。 我想做的是从图库中获取图像或从相机中获取图像,然后插入edittext,其中可能包含文本。(例如,文本……文本……文本……[图像])Android 如何从多媒体资料中获取图像或从相机中获取图像并将其插入编辑文本?,android,image,camera,android-edittext,Android,Image,Camera,Android Edittext,我是Android编程新手。 我想做的是从图库中获取图像或从相机中获取图像,然后插入edittext,其中可能包含文本。(例如,文本……文本……文本……[图像]) 获取图像并将其插入edittext的选定光标点的代码应该如何执行?您可以使用两种方法执行此操作 1) 带SpannableString SpannableString ss = new SpannableString("abc\n"); Drawable d = img.getDrawable(); d.setBou
获取图像并将其插入edittext的选定光标点的代码应该如何执行?您可以使用两种方法执行此操作 1) 带
SpannableString
SpannableString ss = new SpannableString("abc\n");
Drawable d = img.getDrawable();
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
ss.setSpan(span, 0, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
editText.setText(ss);
2) 使用CompoundDrawablesWithIntrinsicBounds
editText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.image, 0, 0, 0);
尝试以编程方式执行以下操作:
EditText et_EditImage = (EditText)findViewById(R.id.et_EditImage);
et_EditImage.setCompoundDrawables(null, null, getResources().getDrawable(R.drawable.tick), null);
请尝试在XML文件中执行此操作:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/search_bar"
android:drawablePadding="8dp"
android:paddingLeft="30dp"
android:paddingRight="10dp"
android:singleLine="true" >
<requestFocus />
</EditText>
<Button
android:id="@+id/searchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_margin="10dp"
android:background="@drawable/icon_magnify" />
<Button
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_margin="8dp"
android:background="@drawable/icon_remove" />
</FrameLayout>
我发现在上,Yu只能在edittext中设置图像的路径。。不是很多年前我做过的。我正在开发一个消息应用程序。我所做的是在编辑文本中添加笑脸,这些笑脸图标是图像。但是我看到了一个允许这种操作的应用程序。非常感谢你!我尝试了许多解决方案,它们都奏效了!我很高兴听你这么说@YoungJunChoi接受这个问题,以便将来其他用户可以解决相同的问题。感谢您的帮助!这对我帮助很大!