zoukankan      html  css  js  c++  java
  • Android基本组件TextView和EditView

    1.TextView

    用于在屏幕上显示文本,可以显示单行文本,多行文本,和带图像的文本。

    常用xml属性

    (1)android:autoLink,用于指定是否将指定的文本转换为可单机的超链接形式,其属性值有none,web,email,phone,map和all

    (2)android:drawableBottom;android:drawableLeft;android:drawableRight;android:drawableTop   分别表示文本框在在各个位置的指定图像

    (3)android:gravity  用于设置文本框内文本的对齐方式 ,其属性值可以组合,用“|”隔开

    (4)android:hint  用于设置当文本框中内容为空的时候,默认的显示的提示文字

    (5)android:inputType  用于指定文本的显示类型,其可选值有 textPassword,textEmailAddress,phone,date等,可以同时指定多个,用“|”隔开。

    (6)android:singleLine 用于指定文本框是否为单行模式。其属性值是true或者false。默认的是false

    (7)android:text  要显示文本的内容

    (8)android:textColor  要显示文本的颜色,其属性值可以是#rgb,#argb,#rrggbb,#aarrggbb格式指定的颜色值。

    (9)android:textSize  用于设置文本框类字体的大小,其属性值由数值和单位组成,其单位可以是px,pt,sp,in,pd。

    (9)android:width;android:height;用于指定文本的宽度高度,已像素为单位。

    TextView的使用实例

    <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/email"
            android:autoLink="email" 
            android:gravity="center"
            android:height="40px"/>
    
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:text="@string/imageTextView" />
        <TextView
            android:id="@+id/textView3"
            android:textSize="20px"
            android:textColor="#0f0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/text" />
        <TextView
            android:id="@+id/textView4"
            android:textSize="20px"
            android:textColor="#f00"
            android:singleLine="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/text" />
    
        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:inputType="textUri"
            android:layout_height="wrap_content"
            android:text="www.baidu.com" />
    

      效果如下

    2 EditText

    EditText是TextView的子类,所以TextView的Xml属性,EditText都有,其中android:inputType属性可以帮助输入框显示合适的类型。

    <requestFocus />会获得焦点,意思就是如果你给某个edittext设置了<requestFocus />标记,并且这个edittext前面没有设置<requestFocus />标记的控件 那么这个edittext就会获得焦点,也就是输入的那个光标。

  • 相关阅读:
    textarea输入限制
    MyBatis 下使用SQLite
    天气预报
    导出Excel、csv
    WDK 常用的几个函数
    Windows 内核 hello world
    内核模式下的文件操作
    Windows 内核编程初涉
    Windows 内地管理
    Windows 内核 同步处理
  • 原文地址:https://www.cnblogs.com/deng-c-q/p/5170394.html
Copyright © 2011-2022 走看看