打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Android开发之TextView文本组件的…
<RelativeLayoutxmlns: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"
   tools:context=".MainActivity">

   <TextView
      android:id="@+id/mytext1"
      android:layout_width="fill_parent"   表示的是宽度占满整个屏幕
      android:layout_height="wrap_content"  表示的是高度自行调整
      android:textColor="#000000"  表示的是文本的颜色
      android:textSize="16px"      表示字体的大小
      android:text="哈尔滨师范大学" 表示我们要显示的字体
      />
   
   <TextView
      android:id="@+id/mytext2"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textColor="#000000"
      android:layout_margin="30px"
      android:textSize="16px"
      android:text="姓名:包汉青" 
      />
   
   <TextView
      android:id="@+id/mytext3"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textColor="#000000"
       android:layout_margin="60px"
      android:textSize="16px"
      android:textStyle="bold"   表示字体加粗
      android:text="中国 黑龙江"
      />
   
   <TextView
      android:id="@+id/mytext4"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textColor="#000000"
      android:layout_margin="90px"  margin的大小
      android:background="@drawable/touxiang" 表示我们的背景图片,@后边为文件夹,touxiang图片名称
      android:text="背景图上显示文字"
      />
   
   该文字显示超链接效果
   <TextView
      android:id="@+id/mytext5"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:  
      android:textColor="#000000"
      android:textSize="15px"
      android:layout_marginTop="200px"
      android:layout_marginLeft="90px"
      android:text="百度  www.baidu.com"
      />

</RelativeLayout>

改进
前边的编写方式,重复内容很多,因此我们需要简化开发。我们就使用到了样式表
 
1,定义一个样式表
在我们的res下边的values当中新建一个mystyle.xml文档

<?xml version="1.0"encoding="utf-8"?>
<resourcesxmlns:android="http://schemas.android.com/apk/res/android">
    <stylename="mystyle">
       <itemname="android:textSize">30px</item>
       <itemname="android:textColor">#000000</item>
       <itemname="android:layout_width">fill_parent</item>
       <itemname="android:layout_height">wrap_content</item>
   </style>
</resources>

那我们如何引用这个文件呢
在我们的<TextView>标签当中加入style="@style/mystyle"
mystyle是mystyle.xml当中的一个name
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android开发:安卓版QQ登陆界面
Android开发笔记(五)— 更改手机窗口底色
listview怎样设置每个Item的高度?
怎么给android 设置边框(tableLayout、表格)
Android 设置页面UI设计
android:布局参数,控件属性及各种xml的作用
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服