Android控件 如何把控

来源:互联网 发布:淘宝挂钩 编辑:程序博客网 时间:2024/06/04 19:24

今天和大家分享一下 有关Android的一些控件及其属性

Textview是Android中最常见的控件了,其意思就是显示文本的控件,而text是其基本的属性,就是显示文字。

1.autolink就是将符合指定格式的文本转化为可单击的超链接模式, android:text=":18273471053。或者发邮件:2896405089@qq.com。百度一下:http://www.xiuxiu.com。"

当执行代码 android:autoLink="all" 就可以将电话,邮件,网址,都自动变成超链接模式, 其取值范围有: none,web,email,map,phone,all(就代表都可转换)

2.singleline 为true时,就表示这个控件只能一行,不能换行,但基本已被淘汰

3.lines 默认占几行,当lines=1时就等同于singleline

4.minlines 最少占几行

5.textColor 字体颜色

6.textSize 字体大小

7.textStyle 字体风格,如粗体斜体

8.background 背景颜色,可以是颜色也可以是图片

9.typeface 系统默认三种字体,但也可以自己下载字体,也被成为自定义字体,需要把字体文件(.ttf)放在/assets目录下面,然后用代码控制。

其代码就是  :Typeface typeface=Typeface.createFromAsset(getAssets(),"STCAIYUN.TTF");
        tv_main_text.setTypeface(typeface);   其中“STCAIYUN.TTF”就是你放在assets中的字体文件名

10.ellipsize,就是文本框只有一行时,但是字数太多,超过屏幕大小就通过这个属性来控制,其中有none,start,middle,end,超过时,就会以.... 来显示,有个特殊的例子是marquee(跑马灯),就是可以缓缓通过一整行,可以动的,但需要加上三个属性。

 android:focusable="true"
 android:focusableInTouchMode="true"
 android:clickable="true"

11.drawable**(方位名:right,left,top,bottom),设置文本框的icon(图标)


二:再来说一下EditText(编辑框)的一些属性,是Textview的子类,他的属性edittext也可以用的

1.InputType 后面接你想要此框的输入类型,如果

android:inputType="numberPassword" 便是输入的是密码框,并且只能值数字类型
2.hint,提示字符信息,当你鼠标一上去,它便会消失
下面再和分享一下 Android中的资源,所谓资源指的便是res文件夹下的xml文件,每种xml文件都对应的是一种资源

1.shape ,Shape资源用来定义一些基本的几何图形(椭圆,矩形,圆形),如

android:shape="rectangle(矩形)"(oval(椭圆),line(线型),ring(圆形))
shape是在最上面的,是一个控件的基本属性,基本模型,而子节点就是对它的模型进行加工 修饰
下面说一下它的子节点:
1.corners:定义几何图的四个角的弧度
<corners    android:bottomLeftRadius="50dp"    android:bottomRightRadius="50dp"    android:topLeftRadius="50dp"    android:topRightRadius="50dp"    ></corners>
就将四个角的弧度不再是正变形
2.gradient定义使用颜色渐变填充,一般指背景颜色,
<gradient    android:startColor="#8cff00"  前颜色    android:centerColor="#ffd500"  中颜色    android:endColor="#ff00e5"   后颜色    android:angle="90"   方向角度,必须是45的整倍数,(0从左到右,默认0,90从上到下)   android:type="linear"  渐变类型,linear线性渐变(默认),redial,径向渐变,一定要指定android:gradientRadius 属性

    ></gradient>
3.pading定义几何形状的内间距,
<padding    android:left="10dp"    android:top="5dp"    android:bottom="5dp"    ></padding>
4.size 定义几何形状的大小
5.solid,使用单种颜色进行填充
<solid    android:color="#ff0000"    ></solid>
6.stroke,定义几何形的边状,
<stroke    android:color="#000000"   边框颜色    android:width="2dp"       边框粗细    android:dashGap="10dp"     虚线间距     android:dashWidth="10dp"   虚线宽度    ></stroke>

最后,再说一下 Selector选择器的作业,即就是在不同状态下控制控件的样式,记住,获取焦点状态的资源,必须放在第一行
 <item     android:drawable="@drawable/et_shape1"     android:state_focused="false"     ></item><item    android:drawable="@drawable/et_shape2"    android:state_focused="true"    ></item>
当没有得到焦点的时候就是shape1的资源
当得到焦点的时候就是shape2的资源。
欢迎多多指点。。。。



原创粉丝点击