Android控件笔记——在界面中显示及输入文本信息

本文详细介绍了Android开发中常用的TextView和EditText控件及其属性设置,包括控件ID、布局宽度和高度、文本内容、文本大小、文本颜色及背景等,并通过实例展示了如何使用这些属性进行界面布局。

1、TextView:显示文本框控件

    常用属性:android:id     控件的id

        android:layout_width     控件的宽度

        android:layout——height        空间的高度

        android:text      文本内容

        android:textSize     文本大小

        android:textColor     文本颜色

        android:background     控件背景

2、EditText:输入文本框

    常用属性:android:id     控件的id

        android:layout_width     控件的宽度

        android:layout——height        空间的高度

        android:text      文本内容

        android:testSize     文本大小

        android:textColor     文本颜色

        android:background     控件背景

        android:hint     输入提示文本

        android:inputType     输入文本类型

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
<!--android:layout_width的参数值: 
warp_content:包裹实际文本内容 ,文本多宽他就有多宽
match_parent:当前控件铺满父类容器-2.3API之后添加的一个属性值
fill_parent:当前控件铺满父类容器-2.3API之前的一个属性值
-->
    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/textView1"
        android:ems="10"
        android:hint="请输入姓名"
        android:textColor="#000000"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/editText1"
        android:layout_alignBottom="@+id/editText1"
        android:layout_alignParentLeft="true"
        android:text="姓名:"
        android:textColor="#000000"
        android:textSize="30sp" />

</RelativeLayout>

225123_AkwI_2725918.jpg

转载于:https://my.oschina.net/CoderBleak/blog/673703

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值