TextView是最熟悉的控件了吧,一开始学安卓就用它,关于它的属性很多,用到的时候百度就行,不用刻意去记忆,下面说一下比较常用的几个用法。
1.加边框
原始的TextView控件不太美观,我们要可以美化一下,比如加各种形状的边框如下
方法:自己写一个ShapeDrawable的资源文件,放到drawable文件夹下,然后将TextView将blackgroung 设置位这个资源即可。
shapeDrawable资源文件的几个节点以及属性介绍:
<solid android:color="xxx"/>设置背景颜色
<stroke android:width="xxx" android:color="xxx"/>设置边框的粗细和颜色
<padding android:left="xxx"/>设置边距
<corners android:topLeftRadius="xxx"/>设置圆角
<gradient> 这个是设置渐变色的
代码示例:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">//矩形
<corners android:radius="60dip" />//圆角半径60
<stroke android:width="0dp" />//线宽0
<solid android:color="@color/tab_unpress" />//背景颜色
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="5dp" />
<solid android:color="@color/main_color" />
</shape>
布局文件:
<TextView
android:id="@+id/tv_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/round_shape_maincolor"//这里
android:textSize="16sp" />
2.带图片(drawableXxx)的TextView:
设置图片的核心其实就是:
drawableTop(上),drawableButtom(下),drawableLeft(左),drawableRight(右) 另外,你也可以使用drawablePadding来设置图片与文字间的间距!
具体请看:http://www.runoob.com/w3cnote/android-tutorial-textview.html