Android之TextView组件学习
2023-09-27 14:20:54 时间
一、基础学习
1.findViewById返回View类,该类是所有View组件的父类。
2.子类比父类拥有更多的属性和方法,不过子类找不到的话去父类找
3.marquee:华盖,跑马灯效果;orientation:方向。
4.setContentView使用布局文件
5.在TextView中如果text是“张朋飞”,而maxLength是2,那么会截取,只显示“张朋”。
二、实例
1.第一个
1: <?xml version="1.0" encoding="utf-8"?>2: <resources>3: <string name="hello">Hello World, MyTextViewDemo!</string>4: <string name="app_name">文本显示组件:TextView</string>5: </resources>6:
1: <?xml version="1.0" encoding="utf-8"?>2: <LinearLayout3: xmlns:android="http://schemas.android.com/apk/res/android"4: android:orientation="vertical"5: android:layout_width="fill_parent"6: android:layout_height="fill_parent">7: <!-- 注释不能放在组件当中,会报错
8: textSize: android 中字头的大小不是按几号字来区分的,因为那是微软的标准,9: 而在android中我们是以像素等基本的物理单位来衡量的。10: layout_margin是控件之间的距离,padding是控件和其中子件的距离11: -->12: <TextView13: android:id="@+id/mytext1"14: android:layout_width="fill_parent"15: android:layout_height="wrap_content"16: android:textColor="#FFFF00"17: android:textSize="12px"18: android:text="北京魔乐科技软件学院(MLDN)" />19: <TextView20: android:id="@+id/mytext2"21: android:layout_width="fill_parent"22: android:layout_height="wrap_content"23: android:layout_margin="30px"24: android:text="网址:www.mldnjava.cn" />25: <TextView26: android:id="@+id/mytext3"27: android:layout_width="fill_parent"28: android:layout_height="wrap_content"29: android:layout_marginTop="100px"30: android:text="李兴华老师"31: android:maxLength="3"/>32: <TextView33: android:id="@+id/mytext4"34: android:layout_width="wrap_content"35: android:layout_height="wrap_content"36: android:background="@drawable/logo"37: android:textColor="#0000FF"38: android:textStyle="bold"39: android:text="这是在背景上的文字信息" />40: </LinearLayout>41:
2.第二个
1: <?xml version="1.0" encoding="utf-8"?>2: <LinearLayout3: xmlns:android="http://schemas.android.com/apk/res/android"4: android:orientation="vertical"5: android:layout_width="fill_parent"6: android:layout_height="fill_parent">7: <!-- 有人说网址后面必须加空格或者换行,否则地址就包含网址2字
8: autoLink 可选值(none/web/email/phone/map/all),9: autoLink 是针对里面输入的内容的格式。当设置成 "web" 格式时,可以识别 "http://" 开头的文本,10: 当用户点击时,可以自动打开浏览器。同理,设置成"phone" "email" 格式时,11: 当遇到 "+860757XXXXXXXX" 电话号码时,用户点击会自动拨打电话,12: 遇到"XXX@csdn.net" E-mail 格式时,用户点击会触发 email 功能。13: -->14: <TextView15: android:id="@+id/msg"16: android:layout_width="fill_parent"17: android:layout_height="wrap_content"18: android:autoLink="all"19: android:textColor="#FFFF00"20: android:textSize="45px"21: android:text="网址:www.mldnjava.cn" />22: </LinearLayout>23:
3.第三个
1: <?xml version="1.0" encoding="utf-8"?>2: <LinearLayout3: xmlns:android="http://schemas.android.com/apk/res/android"4: android:orientation="vertical"5: android:layout_width="fill_parent"6: android:layout_height="fill_parent">7: <TextView8: android:id="@+id/msg"9: style="@style/msg_style"10: android:text="网址:www.mldnjava.cn" />11: </LinearLayout>12:
1: <?xml version="1.0" encoding="utf-8"?>2: <resources>3: <style name="msg_style">4: <item name="android:textSize">45px</item>5: <item name="android:textColor">#FFFF00</item>6: <item name="android:autoLink">all</item>7: <item name="android:layout_width">fill_parent</item>8: <item name="android:layout_height">wrap_content</item>9: </style>10: </resources>11:
相关文章
- Android 之 四大组件、六大布局、五大存储
- Android RecyclerView (十)组件化封装
- Android中的Service组件具体解释
- IDEA Android 表格布局(TableLayout)示例
- Android 组件化(二)注解与注解处理器、组件通讯
- Android组件化开发——从零开始教你分析项目需求并实现
- Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件
- 《移动安全》(1)Android开发基础:安卓操作系统架构与应用程序组件
- 《Android开发基础教程》——6.3节GridView界面组件——表格展示
- Android Jetpack组件之Lifecycles库详解
- android 开源项目集合
- Android多媒体开发(3)————使用Android NKD编译havlenapetr-FFMpeg-7c27aa2
- Android_Service组件详解
- Android API 中文(76)——AdapterView.OnItemLongClickListener
- Android系统Surface机制的SurfaceFlinger服务渲染应用程序UI的过程分析
- 解开Android应用程序组件Activity的"singleTask"之谜
- Android Application的Gradle说明
- android开发 WriteUTF与readUTF 原理
- Android事件处理第一节(View对Touch事件的处理)
- android四大组件之四-BroadCast实现原理分析
- android环境下解决java.io.IOException: Malformed ipv6异常的方法
- Android深入四大组件(七)Service的绑定过程
- Eclipse中Android单元测试
- Unity Android 之 应用签名发布 Publishing Settings 中创建和自定义 keystore 的简单方法(内附说明和操作步骤)