文章目录

  • (一)继承关系图
  • (二)标签常用属性
    • (三)教学案例:标签演示

(一)继承关系图

  • TextView是View的子类

(二)标签常用属性

(三)教学案例:标签演示

1、创建安卓应用

  • 基于Empty Activity模板创建安卓应用 - TextViewDemo

    2、字符串资源文件
  • 字符串资源文件strings.xml

    3、自定义边框配置文件
  • 在drawable目录里创建自定义边框配置文件custom_border.xml

    下面展示一些 内联代码片
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><corners android:radius="5dp" /> <!--圆角--><solid android:color="#dddddd" /> <!--填充色--><strokeandroid:width="1dp"android:color="#555555" /> <!--边界宽度及颜色--><paddingandroid:bottom="10dp"android:left="10dp"android:right="10dp"android:top="10dp" /> <!--内边距--><gradientandroid:centerColor="#ffff00"android:endColor="#00ff00"android:startColor="#aaaaaa" /> <!--渐变色-->
</shape>

4、主布局资源文件

  • 主布局资源文件 - activity_main.xml

    下面展示一些 内联代码片
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#000000"android:orientation="vertical"android:padding="10dp"tools:context=".MainActivity"><TextViewandroid:id="@+id/tv_normal"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/normal"android:textColor="@android:color/holo_blue_bright"android:textSize="15sp"android:textStyle="normal" /><TextViewandroid:id="@+id/tv_bold"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/bold"android:textColor="@android:color/holo_green_light"android:textSize="15sp"android:textStyle="bold" /><TextViewandroid:id="@+id/tv_italic"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/italic"android:textColor="@android:color/holo_orange_light"android:textSize="15sp"android:textStyle="italic" /><TextViewandroid:id="@+id/tv_bold_italic"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/bold_italic"android:textColor="@android:color/holo_purple"android:textSize="15sp"android:textStyle="bold|italic" /><!--分割线--><Viewandroid:layout_width="match_parent"android:layout_height="1dp"android:layout_marginTop="5dp"android:layout_marginBottom="5dp"android:background="#aaaaaa" /><TextViewandroid:id="@+id/tv_all_caps"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/all_caps"android:textAllCaps="true"android:textColor="#ffffff"android:textSize="15sp"android:textStyle="normal" /><TextViewandroid:id="@+id/tv_theorem"android:layout_width="wrap_content"android:layout_height="40dp"android:layout_marginTop="10dp"android:gravity="center_vertical"android:text="@string/theorem"android:textColor="@android:color/holo_red_light"android:textSize="20sp" /><TextViewandroid:id="@+id/tv_equation"android:layout_width="wrap_content"android:layout_height="40dp"android:layout_marginTop="10dp"android:gravity="center_vertical"android:text="@string/equation"android:textColor="@android:color/holo_green_dark"android:textSize="20sp" /><!-- 分隔线 --><Viewandroid:layout_width="match_parent"android:layout_height="1dp"android:layout_marginTop="5dp"android:layout_marginBottom="5dp"android:background="#aaaaaa" /><TextViewandroid:id="@+id/tv_web"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:autoLink="web"android:text="网址:http://www.baidu.com"android:textColor="@android:color/holo_orange_light"android:textSize="15sp" /><TextViewandroid:id="@+id/tv_email"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:autoLink="email"android:text="邮箱:maths007@163.com"android:textColor="@android:color/holo_green_light"android:textSize="15sp" /><TextViewandroid:id="@+id/tv_phone"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:autoLink="phone"android:text="电话:15892921170"android:textColor="@android:color/holo_red_light"android:textSize="15sp" /><!-- 分隔线 --><Viewandroid:layout_width="match_parent"android:layout_height="1dp"android:layout_marginTop="5dp"android:layout_marginBottom="5dp"android:background="#aaaaaa" /><TextViewandroid:id="@+id/tv_bordered_text"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:background="@drawable/custom_border"android:text="带边框的文本:永不放弃的梦想"android:textColor="#ff0000"android:textSize="15sp" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="160dp"android:gravity="center"android:orientation="horizontal"><!--图片标签--><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:drawableLeft="@mipmap/ic_launcher"android:gravity="center"android:text="@string/android"android:layout_marginRight="10dp"android:textColor="#ffffff"android:textSize="18sp" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:drawableTop="@mipmap/ic_launcher"android:gravity="center"android:text="@string/android"android:layout_marginRight="10dp"android:textColor="#ffffff"android:textSize="18sp" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:drawableBottom="@mipmap/ic_launcher"android:gravity="center"android:text="@string/android"android:layout_marginRight="10dp"android:textColor="#ffffff"android:textSize="18sp" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:drawableRight="@mipmap/ic_launcher"android:gravity="center"android:text="@string/android"            android:textColor="#ffffff"android:textSize="18sp" /></LinearLayout>
</LinearLayout>
  • 查看效果

    5、主界面类实现功能
  • 主界面类 - MainActivity
  • 声明变量
  • 通过资源标识符获取控件实例
  • 显示勾股定理
  • 显示化学方程式

```javascript
package net.hw.textview;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;public class MainActivity extends AppCompatActivity {private TextView tvTheorem;private TextView tvEquation;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// 利用布局资源文件设置用户界面setContentView(R.layout.activity_main);// 通过资源标识符获取控件实例tvTheorem = findViewById(R.id.tv_theorem);tvEquation = findViewById(R.id.tv_equation);// 显示勾股定理(毕达哥拉斯定理)tvTheorem.setText(Html.fromHtml("勾股定理:a<sup>2</sup> + b<sup>2</sup> = c<sup>2</sup>"));// 显示化学方程式tvEquation.setText(Html.fromHtml("化学方程式:2H<sub>2</sub> + O<sub>2</sub> = 2H<sub>2</sub>O"));}
}

6、启动应用,查看效果

  • 查看标签的各种显示效果

安卓Android Studio标签相关推荐

  1. 如何在安卓(Android studio)项目中导入模块、jar包、和aar包

    安卓(Android studio)编程中,我们常需要引用"别人写的功能",以扩展app的功能,"别人写的功能"主要有模块.jar包.和aar包三种方式. 下面 ...

  2. java android 相册_基于安卓Android studio相册备份及管理系统的设计

    基于安卓Android studio相册备份及管理系统的设计(论文10000字,程序代码) 摘要:时代在不断地进步与发展着,用户手中的移动中终端越来越多的占据了人们的生活,可以说人们现在是十分依赖手机 ...

  3. 安卓Android Studio开发IDE的安装

    安卓开发IDE的安装 1.进入官网 https://developer.android.google.cn/studio 可以在以下的操作系统开始 Android 应用程序开发: Microsoft® ...

  4. 基于安卓android studio 的 菜谱食谱APP设计

    一 项目概述 菜谱APP或者食谱APP 是基于安卓开发的一个APP,项目包含前台安卓端和后台管理系统,前台安卓端可以进行 查看推荐菜谱,菜谱搜索,收藏菜品 ,菜品排行榜,菜品详情,个人中心,基本信息, ...

  5. 安卓学习笔记 1.1 安卓Android Studio应用

    ​ Android Studio下载安装.创建第一个APP上课笔记步骤: 一.下载Android Studio 二.安装Android Studio 三.配置Android Studio 四.创建第一 ...

  6. 安卓Android studio国际化方法插件安装---快速翻译工具

    internationalization (国际化)简称 i18n,因为在i和n之间还有18个字符,localization(本地化 ),简称L10n. 一般用语言_地区的形式表示一种语言,如 zh_ ...

  7. 安卓Android Studio布局文件分类存放,java文件分类存放

    备注:此备注将会存在本人的每一条博客,将会定期更改 1.使用的软件是Android studio 版本是3.5 当项目比较大的时候文件很多很复杂,这个时候就可以把一些布局文件进行归类存放 问题是我们自 ...

  8. 安卓Android Studio Button按钮background不生效无效问题

    今天又是无语的一天...... 在学习安卓按钮这部分的时候,我新建了xml资源文件用来专门配置按钮的样式: <?xml version="1.0" encoding=&quo ...

  9. 关于安卓Android studio Didn't find class com.xx.MainActivity on path: DexPathList[[zip……的解决

    1.我的问题 首先说一下我的问题,我写的项目在安卓5.0以上的手机上运行的时候没有任何问题,但是在安卓4.4的手机上确直接闪退,报错Didn't find class "com.xx.Mai ...

最新文章

  1. dubbo分布式事务解决方案_spring boot 分布式事务解决方案
  2. Spring MVC快速入门
  3. System.out.println与System.err.println的区别
  4. css中margin:0 auto没作用
  5. Myslq 之创建数据表
  6. android 评论发表情,安卓微信朋友圈怎么评论发表情包 微信朋友圈评论发表情包方法...
  7. ai人工智能让女神_人工智能可能只会让你兴奋不已
  8. 当当购书额外优惠,还有想看的书未入手?这次不要再错过了!
  9. Raspberry Pi 4B SSH、VNC及串口连接配置
  10. 确保软件开发生命周期(SDLC)的安全
  11. 弘辽科技:如何给抖音视频拟写好标题
  12. GPRS模块 测试项目
  13. 干货!如何在训练中自动识别数据中潜在的不同分布并自适应?——以空间数据为例,应用不限于空间数据...
  14. N76E003模拟EEPROM读取和保存应用配置
  15. Druid 的 WallFilter 抛出 sql injection violation, comment not allow 问题的解决方法
  16. 男神女神配 社区交友网 —— 之 主页 详细解说
  17. CEO、COO、CFO、CTO是什么意思?
  18. 微信直播带货效果怎么样
  19. python代码大全心形盒子简单_python心形代码
  20. nervos联创吕国宁:产业区块链与公链结合才是未来

热门文章

  1. 字节跳动、今日头条、阿里爸爸都在使用Flutter,你还有拒绝的理由?
  2. 如何去掉PDF的密码?这几个方法轻松搞定
  3. python写签到软件_第一个实用python程序——自动填写工作日志、签到
  4. 分布式解决方案-全面解密分布式任务调度平台-XXLJob调度中心集群
  5. mysql和postsql分页数据的区别
  6. 访问学者初到美国,如何快速融入当地生活呢?
  7. Vue 项目导入字体文件
  8. 【企业架构设计实战】业务架构设计
  9. SQL笔试题(持续更新)
  10. 库卡工业机器人负载曲线图_KUKA/库卡工业机器人 KR6 R700 负载6KG 机械臂 臂展7.067M...