Android 如何在文本视图中显示背景图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3759545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display background image in text view
提问by mohan
can anybody tell how to display background image in a TextView
in android?
谁能告诉如何TextView
在android中显示背景图像?
回答by Macarse
If you are working with xmls you can add it as Praveen Chandrasekaran said doing:
如果您正在使用 xmls,您可以像 Praveen Chandrasekaran 所说的那样添加它:
android:background="@drawable/myResouce"
Before that you have to put your image file inside the res/drawable folder.
在此之前,您必须将图像文件放在 res/drawable 文件夹中。
You can also change it from the code doing:
您还可以从代码中更改它:
mTextView.setBackgroundResource(R.drawable.myResouce);
回答by Praveen
add a android:background="@drawable/imagefile"
attribute on your TextView
tag. Before that you have to put your image file inside the res/drawable
folder.
android:background="@drawable/imagefile"
在您的TextView
标签上添加一个属性。在此之前,您必须将图像文件放入res/drawable
文件夹中。
回答by Alberto Hdez
android:background="@drawable/mark"
android:background="@drawable/mark"
Also review.... your background image should be a 9.png and add some paddings for your content
还要....您的背景图片应该是 9.png 并为您的内容添加一些填充
android:layout_marginLeft="10dp" android:layout_marginRight="10dp"
android:layout_height="400dp" android:background="@drawable/mark"
android:paddingTop="5dp" android:paddingBottom="5dp" android:paddingLeft=