文本框组件

文本框组件

新建一个project
在这里插入图片描述

  1. 设置文本框内的文本内容

    Android推荐使用字符串资源,而不是直接写死:
    android:text="Hello World!"

    字符串资源位置:res>values>strings.xml
    默认自动生成的代码如下:

    <resources>
        <string name="app_name">Consistent</string>
    </resources>
    
    

    可以向里面添加字符串资源如<string name="demo1">奋斗</string>

    <resources>
        <string name="app_name">Consistent</string>
    
        <string name="demo1">奋斗</string>
    
    </resources>
    
    

    设置好之后可以在布局文件中引用刚设置好的字符串资源:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        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="com.example.hahaha.consistent.MainActivity">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            
            android:text="@string/demo1"  # 引用上面设置的“奋斗”字符串资源
            />
    </RelativeLayout>
    
    

    设计视图显示:
    在这里插入图片描述

  2. 设置文本框中文本内容的大小、颜色

  • 文本大小设置:android:textSize="27sp"

  • 文本内容太多,可以通过设置单行文本框android:singleLine="true"省略后面的显示

  • 在这里插入图片描述

  • 文本颜色设置:android:textColor="#FF0000"

    不知道颜色代码时,可以随机设置一个颜色,然后通过点击左下角的颜色代码小框,来在下面的颜色界面中通过拖动滑动条来选择自己想要的颜色代码:

    在这里插入图片描述
    建议:类似字符串设计,在res>values>colors.xml中添加颜色,然后在布局文件中调用颜色

  1. 实例:实现QQ手机聊天列表页面

    在project中新建一个module:

    在这里插入图片描述
    将聊天框背景提前放如res>drawable中,
    res>layout>activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <GridLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        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"
    
        android:background="@mipmap/chatbg" # 聊天背景
    
        tools:context="com.example.qqlist.MainActivity">
    
    	# 第一个文本框
        <TextView
            android:id="@+id/text1"
            android:text="嗨喽!早上好!"
            android:background="@drawable/chat1"
            android:textColor="#FFFFFF"
            android:textSize="18sp"
            android:layout_gravity="end"
            android:layout_columnSpan="4"
            android:layout_row="0"
            android:layout_column="1"
            android:layout_marginRight="5dp"
            android:layout_marginBottom="20dp"
        />
        # 第一个头像
        <ImageView
            android:id="@+id/imageview1"
            android:src="@mipmap/t1"
            android:layout_row="0"
            android:layout_column="5"
            />
    
    	# 第2个头像
        <ImageView
            android:id="@+id/imageview2"
            android:src="@mipmap/t2"
            android:layout_row="1"
            android:layout_column="0"
            />
         # 第2个文本框
        <TextView
            android:id="@+id/text2"
            android:text="你好呀!我们一块去上课吧!"
            android:textColor="#FFFFFF"
            android:textSize="18sp"
            android:background="@drawable/chat2"
            android:layout_row="1"
            android:layout_marginBottom="20dp"
            />
    
    	# # 第3个文本框
        <TextView
            android:id="@+id/text3"
            android:text="我们在哪个教室上课?"
            android:background="@drawable/chat1"
            android:textSize="18sp"
            android:textColor="#FFFFFF"
            android:layout_gravity="end"
            android:layout_columnSpan="4"
            android:layout_row="2"
            android:layout_column="1"
            android:layout_marginRight="5dp"
            android:layout_marginBottom="20dp"
            />
           ## 第3个头像
        <ImageView
            android:id="@+id/imageview3"
            android:src="@mipmap/t1"
            android:layout_row="2"
            android:layout_column="5"
            />
    
    	# # 第4个头像
        <ImageView
            android:id="@+id/imageview4"
            android:src="@mipmap/t2"
            android:layout_row="3"
            android:layout_column="0"
            />
           # # 第4个文本框
        <TextView
            android:id="@+id/text4"
            android:text="那我们一会买完早饭一块去教室。"
            android:textColor="#FFFFFF"
            android:background="@drawable/chat2"
            android:textSize="18sp"
            android:layout_row="3"
            android:layout_marginBottom="20dp"
            />
    
    # # 第5个文本框
        <TextView
            android:id="@+id/text5"
            android:text="好的好的!一会教室见!!"
            android:background="@drawable/chat1"
            android:textSize="18sp"
            android:textColor="#FFFFFF"
            android:layout_gravity="end"
            android:layout_columnSpan="4"
            android:layout_row="4"
            android:layout_column="1"
            android:layout_marginRight="5dp"
            android:layout_marginBottom="20dp"
            />
          # # 第5个头像
        <ImageView
            android:id="@+id/imageview5"
            android:src="@mipmap/t1"
            android:layout_row="4"
            android:layout_column="5"
        />
    
    </GridLayout>
    
    

    运行结果:
    在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ajax框架介绍   虽然大部分开发人员在过去使用过XMLHttp或者使用Iframe来加载数据,但仅到现在我们才看到传统的开发人员和公司开始采用这些技术。就像新的编程语言或模型伴随着更多的痛苦,开发人员需要学习新的技巧及如何最好利用这些新技术。   AJAX模式   许多重要的技术和AJAX开发模式可以从现有的知识中获取。例如,在一个发送请求到服务端的应用中,必须包含请求顺序、优先级、超时响应、错误处理及回调,其中许多元素已经在Web服务中包含了,就像现在的SOA。AJAX开发人员拥有一个完整的系统架构知识。同时,随着技术的成熟还会有许多地方需要改进,特别是UI部分的易用性。   AJAX开发与传统的CS开发有很大的不同。这些不同引入了新的编程问题,最大的问题在于易用性。由于AJAX依赖浏览器的JavaScript和XML,浏览器的兼容性和支持的标准也变得和JavaScript的运行时性能一样重要了。这些问题中的大部分来源于浏览器、服务器和技术的组合,因此必须理解如何才能最好的使用这些技术。   综合各种变化的技术和强耦合的客户服务端环境,AJAX提出了一种新的开发方式。AJAX开发人员必须理解传统的MVC架构,这限制了应用层次之间的边界。同时,开发人员还需要考虑CS环境的外部和使用AJAX技术来重定型MVC边界。最重要的是,AJAX开发人员必须禁止以页面集合的方式来考虑Web应用而需要将其认为是单个页面。一旦UI设计与服务架构之间的范围被严格区分开来后,开发人员就需要更新和变化的技术集合了。
Ajax框架介绍   虽然大部分开发人员在过去使用过XMLHttp或者使用Iframe来加载数据,但仅到现在我们才看到传统的开发人员和公司开始采用这些技术。就像新的编程语言或模型伴随着更多的痛苦,开发人员需要学习新的技巧及如何最好利用这些新技术。   AJAX模式   许多重要的技术和AJAX开发模式可以从现有的知识中获取。例如,在一个发送请求到服务端的应用中,必须包含请求顺序、优先级、超时响应、错误处理及回调,其中许多元素已经在Web服务中包含了,就像现在的SOA。AJAX开发人员拥有一个完整的系统架构知识。同时,随着技术的成熟还会有许多地方需要改进,特别是UI部分的易用性。   AJAX开发与传统的CS开发有很大的不同。这些不同引入了新的编程问题,最大的问题在于易用性。由于AJAX依赖浏览器的JavaScript和XML,浏览器的兼容性和支持的标准也变得和JavaScript的运行时性能一样重要了。这些问题中的大部分来源于浏览器、服务器和技术的组合,因此必须理解如何才能最好的使用这些技术。   综合各种变化的技术和强耦合的客户服务端环境,AJAX提出了一种新的开发方式。AJAX开发人员必须理解传统的MVC架构,这限制了应用层次之间的边界。同时,开发人员还需要考虑CS环境的外部和使用AJAX技术来重定型MVC边界。最重要的是,AJAX开发人员必须禁止以页面集合的方式来考虑Web应用而需要将其认为是单个页面。一旦UI设计与服务架构之间的范围被严格区分开来后,开发人员就需要更新和变化的技术集合了。
Android Studio中,文本框组件通常指的是EditText组件。在XML布局文件中,可以使用以下代码来创建一个EditText组件: ``` <EditText android:id="@id/ed1" android:layout_width="358dp" android:layout_height="30dp" android:layout_gravity="center" android:layout_marginLeft="10dp" android:ellipsize="end" android:gravity="center" android:hint="搜索" android:imeOptions="actionSearch" android:inputType="textPersonName" android:maxLines="1" android:singleLine="true" android:text="请输入内容" android:textSize="15sp" /> ``` 这个代码会创建一个具有特定属性和样式的文本框组件。其中,`android:hint`属性用于添加在编辑框中的提示信息,`android:inputType`属性用于设置编辑框中文本内容的类型,`android:drawableLeft`和`android:drawableRight`属性用于在编辑框中的文本内容的左右侧绘制图像,`android:drawablePadding`属性用于设置图像与文本内容的间距,`android:lines`属性用于设置编辑框的最大行数等等。此外,你还可以通过在drawable文件夹中创建一个名为"round_button.xml"的资源文件来设置编辑框的背景样式。这个资源文件的内容可以使用以下代码示例: ``` <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#FFFFFF"></solid> <corners android:radius="3dp" android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" /> <stroke android:width="1dip" android:color="@color/blue" /> </shape> ``` 这个代码会创建一个圆角矩形的背景样式,并设置颜色和边框。你可以根据自己的需要更改这些属性的值。通过将这个资源文件与`android:background`属性绑定,你可以将这个背景样式应用到编辑框组件上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值