Android常用控件之TextView、EditText、Shape外形资源、Selector选择器
来源:互联网 发布:python的idle在哪 编辑:程序博客网 时间:2024/06/01 20:20
以上就是四种常用控件
接下来我用一个案例来具体讲一下怎么用:
这是案例截图,当文本输入框获得焦点时整个背景包括文本输入框变蓝色,失去焦点时为绿色
代码如下:
这里我用的是桢布局,先把文本框和背景铺在下面,然后再铺上文字
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入用户名" android:inputType="text" android:background="@drawable/et_selector"//引用Selector选择器 /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@mipmap/icon_user"//在文字的左边引用图标 android:layout_marginLeft="15dp"//设置距离屏幕左端的距离 android:layout_marginTop="5dp"//设置距离屏幕上端的距离 android:text="用户名:" android:textSize="20sp"//设置文字的大小 /> </FrameLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp" > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入密码" android:inputType="text" android:background="@drawable/et_selector" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@mipmap/icon_user" android:layout_marginLeft="15dp" android:layout_marginTop="5dp" android:text=" 密码:" android:textSize="20sp" /> </FrameLayout></FrameLayout>再引用选择器之前,我们需要创建一个选择器
在drawable文件夹下创建et_selector文件,内容如下
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:drawable="@drawable/et_shape"></item>//得到焦点时引用et_shape外形资源 <item android:state_focused="false" android:drawable="@drawable/et_shape2"></item>//失去焦点时引用et_shape2外形资源</selector>
同样的,引用外形资源时,我们先在drawable文件夹下创建et_shape和et_shape2资源文件
et_shape:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!--设置背景颜色--> <solid android:color="#00e6ff" > </solid> <!--弧度--> <corners android:radius="30dp" ></corners> <!--内边距--> <padding android:top="5dp" android:bottom="5dp" android:left="110dp" android:right="5dp" ></padding> <!--边框--> <stroke android:width="2dp" android:color="#000000" > </stroke></shape>et_shape2:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#1eff00" > </solid> <!--弧度--> <corners android:radius="30dp" ></corners> <!--内边距--> <padding android:top="5dp" android:bottom="5dp" android:left="110dp" android:right="5dp" ></padding> <!--边框--> <stroke android:width="2dp" android:color="#000000" > </stroke></shape>然后就可实现上述效果了
阅读全文
0 0
- Android常用控件之TextView、EditText、Shape外形资源、Selector选择器
- Android 常用控件(TextView、EditText)及Shape外形资源、Selector选择器
- TextView 、EditText 、Shape外形资源 、Selector选择器
- Android常用控件(TextView-EditText-Shape-Selector)
- 常用控件(TextView-EditText-Shape-Selector)
- Android04-常用控件(TextView-EditText-Shape-Selector)
- Android初学者的简单登录,利用外形资源和selector选择器
- Android Shape资源文件和Selector选择器使用
- Android常用控件 一(文本控件,android资源,selector选择器)
- Android studio外形资源和选择器解析
- Android基础控件之TextView与EditText
- Android之TextView、EditText控件显示表情图片
- Android控件复习之TextView与EditText
- Android:背景选择器selector及shape详解
- Android常用控件之EditText
- shape修改EditText和Button的外形
- TextView shape 和 selector
- 背景选择器selector/shape
- android常用控件
- weka源码之C45(J48)
- Android Studio导入project和module的方法
- Hibernate 核心技术(四)
- Linux 通过 ODBC 连接 SQL Server2008
- Android常用控件之TextView、EditText、Shape外形资源、Selector选择器
- hud 2087
- 操作系统(7)
- C语言~模拟实现通用冒泡排序
- 【Demo】Windows Service 定时服务
- InsomniaShell
- Android中网络通信基于HTTP、Socket
- trustzone的硬件框架和安全扩展
- socket实现文件传输功能