文档详情

Android控件常见的属性.doc

发布:2017-12-12约7.21千字共8页下载文档
文本预览下载声明
一、TextView控件常见的属性 描述 android:autoLink 设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接。可选值(none/web/email/phone/map/all)。这里只有在同时设置text时才自动识别链接,后来输入的无法自动识别。 android:ems 设置TextView的宽度为N个字符的宽度。参见TextView中此属性的截图 android: scrollHorizontally 设置文本超出TextView的宽度的情况下,是否出现横拉条。 android:singleLine 设置单行显示。如果和layout_width一起使用,当文本不能全部显示时,后面用“…”来表示。如android:text=test_ singleLine android:singleLine=true android:layout_width=20dp将只显示“t…”。如果不设置singleLine或者设置为false,文本将自动换行 android:textColor 设置文本颜色 android: textColorLink 文字链接的颜色. android:textSize 设置文字大小,推荐度量单位”sp”,如”15sp” android:textStyle 设置字形[bold(粗体) 0, italic(斜体) 1, bolditalic(又粗又斜) 2] 可以设置一个或多个,用“|”隔开 android:typeface 设置文本字体,必须是以下常量值之一:normal 0, sans 1, serif 2, monospace(等宽字体) 3] android:height 设置文本区域的高度,支持度量单位:px(像素)/dp/sp/in/mm(毫米) android:width 设置文本区域的宽度,支持度量单位:px(像素)/dp/sp/in/mm(毫米),与layout_width的区别是更加精确。 android:ellipsize 设置当文字过长时,该控件该如何显示。有如下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动) 二、EditText是可编辑的文本框,继承自TextView,因此属性基本相同。EditText中的文字可以编辑而TextView只显示文字,其中的文字不能编辑。EditText和TextView类似于C#中的Label和TextBox控件。 三、Button也继承自TextView,因此也具有TextView的宽和高设置,文字显示等一些基本属性。Button一般会与单击事件联系在一起。为Button注册单击事件有两种方法: ????? 1.通过Button控件的setOnClickListener()方法为Button注册OnClickListener。 ?public class MyActivity extends Activity { ? ? ?protected void onCreate(Bundle icicle) { ? ? ? ? ?super.onCreate(icicle); ? ? ? ? ?setContentView(R.layout.content_layout_id); ? ? ? ? ?final Button button = (Button) findViewById(R.id.button_id); ? ? ? ? ?button.setOnClickListener(new View.OnClickListener() { ? ? ? ? ? ? ?public void onClick(View v) { ? ? ? ? ? ? ? ? ?// Perform action on click ? ? ? ? ? ? ?} ? ? ? ? ?}); ? ? ?} ?} ??????2.通过使用android:OnClick属性在xml布局文件中为Button指定单击事件发生时执行的函数。 ?Button ? ? ?android:layout_height=wrap_content ? ? ?android:layout_width=wrap_content ? ? ?android:text=@string/self_destruct ? ? ?android:onClick=selfDestruct / ????? 当用户点击了Button时,Android系统调用activity的selfDestruct(Vie
显示全部
相似文档