Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 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 Reply

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...