Android开发之初级开发_控件开发--EditText

EditText相关属性:

android:hint="请输入数字!"//设置显示在空间上的提示信息
android:numeric="integer"//设置只能输入整数,如果是小数则是:decimal
android:singleLine="true"//设置单行输入,一旦设置为true,则文字不会自动换行。
android:password="true"//设置只能输入密码
android:textColor = "#ff8c00"//字体颜色
android:textStyle="bold"//字体,bold, italic, bolditalic
android:textSize="20dip"//大小

android:textScaleX="1.5"//控制字与字之间的间距

android:layout_weight="1"//权重,控制控件之间的地位,在控制控件显示的大小时蛮有用的

android:layout_gravity="center_vertical"//设置控件显示的位置:默认top,这里居中显示,还有bottom

android:capitalize //首字母大写

android:phoneNumber //输入电话号码
android:editable //是否可编辑
android:autoLink=”all” //设置文本超链接样式当点击网址时,跳向该网址 

android:cursorVisible设定光标为显示/隐藏,默认显示。

android:maxLength限制显示的文本长度(限制输入字符数量,比如中国的手机号码是11位),超出部分不显示。
android:lines设置文本的行数,设置两行就显示两行,即使第二行没有数据。

android:password以小点”.”显示文本

 

 

首先在drawable文件夹下建立一个名为shape.xml的文件

输入以下内容:

 

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

 

    <!-- 设置填充颜色 -->
    <solid android:color="#00ffff" />
    <!-- 设置为弧形  且半径为14dp -->
    <corners android:radius="14dp" />

 

</shape>

并且在drawable下保存一张图片,且不能超过edittext的控件高度,尽可能的小

下面是布局文件

 

<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="#060"
    android:orientation="vertical"
    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" >

    <!-- 将第一个高宽度设置为0可以去除edittext的焦点 -->

    <EditText
        android:id="@+id/ET_01"
        android:layout_width="0dp"
        android:layout_height="0dp" />

    <EditText
        android:id="@+id/ET_02"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/ET_03"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLength="11" />

    <EditText
        android:id="@+id/ET_04"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="单行且只能输入数字"
        android:inputType="number"
        android:singleLine="true" />

    <EditText
        android:id="@+id/ET_05"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/tupian"
        android:hint="显示一张图片" />

    <EditText
        android:id="@+id/ET_06"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@drawable/shape"
        android:hint="实现圆角" />

</LinearLayout>

 

效果图自己运行

 

 

posted @ 2014-03-26 15:46  loneliness__白色  阅读(133)  评论(0)    收藏  举报