Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

android - 如何在Android文本视图周围添加边框?(How do I put a border around an Android textview?)

是否可以在textview周围绘制边框?

  ask by yamspog translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can set a shape drawable (a rectangle) as background for the view.

(您可以将形状可绘制(矩形)设置为视图的背景。)

<TextView android:text="Some text" android:background="@drawable/back"/>

And rectangle drawable back.xml (put into res/drawable folder):

(和矩形drawable back.xml(放入res / drawable文件夹):)

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
   <solid android:color="@android:color/white" />
   <stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>

You can use @android:color/transparent for the solid color to have a transparent background.

(您可以使用@android:color/transparent作为纯色,以获得透明背景。)

You can also use padding to separate the text from the border.

(您还可以使用填充来将文本与边框分开。)

for more information see: http://developer.android.com/guide/topics/resources/drawable-resource.html

(有关详细信息,请参阅: http//developer.android.com/guide/topics/resources/drawable-resource.html)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...