恰逢暑假,把有关Android的EditText相关内容整理一下:

一、为EditText添加图片

在EditText中添加图片,只需要设置android:drawableLeft、android:drawableRight、android:drawableTop或者android:drawableBottom属性,在xml中即可完成。例如:

    <EditText        android:id="@+id/text"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:hint="hello"        android:drawableLeft="@drawable/search"        />


效果如下:

二、为EditText添加Button

在EditText中添加Button相对麻烦一些,这里实现的方法是利用相对布局RelativeLayout,关键在于设置android:layout_alignBaseline(alignRight、alignLeft、alignTop、alignBottom)属性使Button控件的边缘与EditText的边缘对齐。

    <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"     > <EditText android:id="@+id/searcheidt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:hint="search" /> <Button android:id="@+id/search_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/search"android:layout_alignTop="@id/searcheidt" android:layout_alignRight="@id/searcheidt" android:layout_marginRight="5px" />       </RelativeLayout> 


这里我设置了android:layout_alignTop和 android:layout_alignRight属性,是Button的顶部边缘和右边缘分别于EditText的顶部边缘和右边缘对齐,即可实现(此时搜索图标表示一个按钮,通过设置监听器可以实现相应功能):

三、shape的使用

在android中常常用shape来修改控件的显示属性,比如:圆角、描边之类的。首先,写一个xml文件:edittext_shape.xml

<?xml version="1.0" encoding="UTF-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">     <!--圆角-->    <corners        android:radius="5dp"/>    <!--实心-->    <solid        android:color="#eeeeee"/>    <!--描边-->    <stroke        android:width="1dip"        android:color="#c6cbce"/>    <!--渐变-->    <gradient/></shape>


把以上edittext_shape.xml文件放到drawable文件夹内,然后只需要在设置EditText的background属性即可:

android:background="@drawable/edittext_shape"

如下:

  <EditText        android:id="@+id/text"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:hint="hello"        android:drawableLeft="@drawable/search"        android:background="@drawable/edittext_shape"        />

效果如下:



就先整理这些。。。




更多相关文章

  1. Android:EditText 所有属性
  2. Android(安卓)控件使用参数集锦
  3. Android(安卓)Studio 布局属性笔记
  4. android xml布局文件属性说明
  5. Android中xml布局 详解
  6. android xml属性大全
  7. Android(安卓)资源聚集地
  8. 相对布局相关属性
  9. Android控件笔记——在界面中显示及输入文本信息

随机推荐

  1. Android—— Activity生命周期
  2. Android媒体解码MediaCodec MediaExtract
  3. android客户端从服务器端获取json数据并
  4. Android之Content ProviderII
  5. 淘宝(阿里百川)手机客户端开发日记第一篇
  6. 【Android(安卓)Audio】Android(安卓)Aud
  7. android上下文
  8. Android(安卓)学习教程一 安装eclipse an
  9. 【Android(安卓)界面效果6】Android(安卓
  10. Android(安卓)系统调试接口