Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在string.xml中添加可绘制资源_Android_Android Drawable_Android Resources - Fatal编程技术网

Android 在string.xml中添加可绘制资源

Android 在string.xml中添加可绘制资源,android,android-drawable,android-resources,Android,Android Drawable,Android Resources,我试图在resources string.xml中的字符串(我的字符串名称)中添加一个可绘制的(ic_myimage) <resources> <string name="my_string_name">Here is my image: @drawable/ic_myimage It looks great</string> </resources> 这是我的图片:@drawable/ic_myimage它看起来很棒 这可能吗?我希

我试图在resources string.xml中的字符串(我的字符串名称)中添加一个可绘制的(ic_myimage)

<resources>
    <string name="my_string_name">Here is my image: @drawable/ic_myimage It looks great</string>
</resources>

这是我的图片:@drawable/ic_myimage它看起来很棒
这可能吗?我希望包含字符串其余部分的图像显示在我的文本视图中。(代码如下)


注意:我在另一篇文章中找到了以下内容,但没有成功

<string name="my_string_name">Here is my image: [img src=ic_myimage/] It looks great</string>
这是我的图片:[img src=ic\u myimage/]看起来很棒

我正在使用Android Studio和Kotlin。

很抱歉,图像不可能显示在Textview中。从drawable调用图像的正确方法是使用ImageView

像这个

<ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_gravity="center"
            android:layout_height="200dp"
            android:layout_marginStart="30dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="25dp"
            android:scaleType="centerInside"
            android:layout_marginLeft="100dp"
            android:layout_marginRight="8dp"
            android:background="@drawable/ic_myimage">

</ImageView>

请使用文本视图的drawableStart()方法在文本视图的左侧显示图标。但您不能将图标用作字符串文本。

您可以通过使用类似的可扩展字符串提供文本来实现

//your drawable    
ImageSpan is = new ImageSpan(context, R.drawable.arrow);

//your spannable text "Lorem.... amet"
SpannableString spannableText= new SpannableString("Lorem ipsum dolor sit amet");

//apply image to spannable text 
//0 is the flag
//start and end are the index length where you wantg to put the image
spannableText.setSpan(is, startIndex, End index, 0);

//then, you can  apply this tspannable text to textview
yourTextView.setText(spannableText);

这是解决我问题的最接近的答案。谢谢我还为那些想要Kotlin版本的人更改了它
val-imageSpan=imageSpan(applicationContext,R.drawable.ic_-myimage)val-spannableText=SpannableString(“这是我的图像:ic_-myimage,看起来很棒”)val-keyword=“ic_-myimage”val-index=spannableText.indexOf(关键字);spannableText.setSpan(imageSpan,index,index+keyword.length,0)myTextView.text=spannableText
感谢您的回复。但是我想在同一个textview中添加几个图像,再加上一些字符串。
//your drawable    
ImageSpan is = new ImageSpan(context, R.drawable.arrow);

//your spannable text "Lorem.... amet"
SpannableString spannableText= new SpannableString("Lorem ipsum dolor sit amet");

//apply image to spannable text 
//0 is the flag
//start and end are the index length where you wantg to put the image
spannableText.setSpan(is, startIndex, End index, 0);

//then, you can  apply this tspannable text to textview
yourTextView.setText(spannableText);