android studio design为什么text切换到design时会改变width和height的值

Android TextInputLayout修改提示信息文字颜色
工作中,有时候需要修改TextInputLayout提示信息文字颜色,怎么办呢?谷歌把Design Support Library写的很好。每一个控件的颜色都是直接通过主题颜色绘制的,在 style.xml 中指定。
工作中,有时候需要修改TextInputLayout提示信息文字颜色,怎么办呢?谷歌把Design Support Library写的很好。每一个控件的颜色都是直接通过主题颜色绘制的,在 style.xml 中指定。打开它添加colorAccent 到主题以改变表单的颜色。
&style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"&
&item name="colorAccent"&#3498db&/item&
使用TextInputLayout创建一个登陆界面
1. 实现 TextInputLayout
第一步: 创建一个新的项目
在Android Studio中 选择New & New project 。填入所需的信息然后创建项目。我的例子的target api是17,这是Design Support Library支持的最小api版本。这个级别的api基本上已经支持绝大多数设备了。我把主activity命名为LoginActivity,它的布局文件命名为activity_login.xml。
创建完项目之后,在主activity中把Android Studio自动产生的onCreateOptionsMenu 和onOptionsItemSelected方法删掉。我们要创建的登陆界面不需要菜单所以删掉这些方法是ok的。记得也删掉res/menu目录中的XML 菜单文件。
第二步 :导入Support Library
要使用TextInputLayout控件,你需要导入两个Library。第一个是appcompat-v7,它确保material style可以向后兼容。第二个是Design Support Library。在你的build.gradle文件中,添加如下依赖:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
如果Gradle没有自动询问同步项目,选择build菜单中的Make module 'app' ,或者按F9。这样Android Studio 编译系统会自动获取必要的资源,然后你就能够使用需要的类了。
第三步 :设计用户界面
这个项目的用户界面非常简单。它显示了一个“欢迎”文字(可以很容易替换成logo什么的)与两个EditText元素,一个是为用户名准备的,一个是为密码准备的。布局中还包含了一个触发登陆流程的按钮。背景颜色是扁平风格的灰色。
另一个重要的细节是记得正确设置EditText的inputType属性。第一个EditText的inputType应该设置成textEmail,而第二个应该设置成textPassword。下面是布局的样子:
&LinearLayoutxmlns:android=""
xmlns:tools=""
android:background="#e3e3e3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_horizontal_margin"
tools:context=".LoginActivity"
android:orientation="vertical"&
&RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical"&
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="Welcome"
android:textSize="30sp"
android:textColor="#333333"/&
&/RelativeLayout&
&LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical"&
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"/&
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/&
android:id="@+id/btn"
android:layout_marginTop="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"/&
&/LinearLayout&
&/LinearLayout&
你可能还想去掉app bar,也就是过去说的actionbar,编辑style.xml文件:
&style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"&
第四步: 使用TextInputLayout
我们总算到了本教程最有趣的部分。TextInputLayout控件和LinearLayout完全一样,它只是一个容器。跟ScrollView一样,TextInputLayout只接受一个子元素。子元素需要是一个EditText元素。
&android.support.design.widget.TextInputLayout
android:id="@+id/usernameWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"&
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Username"/&
&/android.support.design.widget.TextInputLayout&
注意这里我在EditText中指定了另一个参数,hint。就如你知道的,这个属性允许你在EditText的内容为空的时候显示一个自定义的提示。一旦用户开始输入,hint会消失。这并不理想,因为用户丢失了他们输入信息的上下文提示。
有了TextInputLayout,这将不再是问题。一个单一的EditText 在输入文字的时候会隐藏hint,而被包含在TextInputLayout中的EditText则会让hint变成一个在EditText上方的浮动标签。同时还包括一个漂亮的material动画。
接下来,我们对password输入框做同样的事情。
&android.support.design.widget.TextInputLayout
android:id="@+id/passwordWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/usernameWrapper"
android:layout_marginTop="4dp"&
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Password"/&
&/android.support.design.widget.TextInputLayout&
现在如果你运行应用,什么也不会发生。当然,EditText的hint会表现的跟预期一致。但是没有material动画也没有浮动标签。为什么会这样?我们还缺少一些代码。
第五步: 设置 Hints
下面是setContentView方法,初始化对theTextInputLayout视图的引用。
final TextInputLayout usernameWrapper = (TextInputLayout) findViewById(R.id.usernameWrapper);
final TextInputLayout passwordWrapper = (TextInputLayout) findViewById(R.id.passwordWrapper);
要让浮动标签动起来,你只需设置一个hint,使用setHint方法:
usernameWrapper.setHint("Username");
passwordWrapper.setHint("Password");
然后你就完成了。你的登陆界面现在很好的遵循了material设计规范。运行项目查看你的登陆界面。
2. 处理错误
TextInputLayout的另一个特色是它可以处理错误。通过验证输入,你可以防止用户输入无效的邮箱地址或者是太短的密码。如果没有验证,后台可能反馈回不正确的结果呈现给用户。对于用户来说既浪费了时间又体验不好。在发送到后台之前你应该先检查输入的正确性。
第一步: 实现 onClick 方法
首先你需要处理按钮的点击。有许多方法处理按钮的点击。其中一种就是写一个自定义的方法然后在xml中通过onClick属性指定,我喜欢setOnClickListener的方式,但这只是个人喜好。
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
我们知道当这个方法调用之后,用户不再需要键盘。不幸的是,如果你不告诉它,安卓不会自动的隐藏虚拟键盘。在onClick方法体中调用hideKeyboard。
private void hideKeyboard() {
View view = getCurrentFocus();
if (view != null) {
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).
hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
第二步 : 输入验证
在设置错误标签之前,我们需要定义什么是错误,什么不是。我们假设用户名必须是一个邮箱地址并且我们想阻止用户输入无效的邮箱地址。
验证邮箱地址有点复杂。我们必须依赖正则表达式。如果你想也可以使用Apache Commons library。
我使用了 上关于邮箱验证的指导,写了如下的正则表达式。
/^[a-zA-Z0-9#_~!$&'()*+,;=:."(),:;&&@\[\]\\]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/
注:这个正则表达式的意思我就不翻译了,如果你不熟悉正则表达式看了也没啥用。
因为我们想验证字符串,我必须依赖Pattern和Matcher两个类。includeava.util.regex 包。实现如下的方法:
private static final String EMAIL_PATTERN = "^[a-zA-Z0-9#_~!$&'()*+,;=:.\"(),:;&&@\\[\\]\\\\]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*$";
private Pattern pattern = pile(EMAIL_PATTERN);
public boolean validateEmail(String email) {
matcher = pattern.matcher(email);
return matcher.matches();
密码的验证简单的多。很多组织为密码的验证采用了不同的策略,但是所有人都会限制最短长度。合理的密码应该不低于6个字符。
public boolean validatePassword(String password) {
return password.length() & 5;
第三步: 获取数据
就如我说的,TextInputLayout只是一个容器,但是和LinearLayout和ScrollView不同,你可以使用一个特殊的方法获得子元素,getEditText,不需要使用findViewById。
public void onClick(View v) {
hideKeyboard();
String username = usernameWrapper.getEditText().getText().toString();
String password = passwordWrapper.getEditText().getText().toString();
第四步: 显示错误
TextInputLayout的错误处理简单快速。需要的方法是setErrorEnabled和setError。
setError设置一个红色的错误消息,显示在EditText的下面。如果传入的参数为null,错误消息将清空。并且它会改变整个EditText控件为红色。
setErrorEnabled开启错误提醒功能。这直接影响到布局的大小,增加底部padding为错误标签让出空间。在setError设置错误消息之前开启这个功能意味着在显示错误的时候布局不会变化。你可以把这两个方法结合起来验证下我所说的。
另一个有趣的事实是如果错误功能未开启但是你调用了传入非null参数的setError,那么setErrorEnabled(true)将自动被调用。
现在我们定义了什么是错误的什么是正确的,也知道了如何获取EditText中的数据以及显示可能的错误,onClick方法的实现就很简单了。
public void onClick(View v) {
hideKeyboard();
String username = usernameWrapper.getEditText().getText().toString();
String password = usernameWrapper.getEditText().getText().toString();
if (!validateEmail(username)) {
usernameWrapper.setError("Not a valid email address!");
} else if (!validatePassword(password)) {
passwordWrapper.setError("Not a valid password!");
usernameWrapper.setErrorEnabled(false);
passwordWrapper.setErrorEnabled(false);
doLogin();
我添加了一个doLogin方法,但是目前它是空的因为这超出了本教程的范围。
public void doLogin() {
Toast.makeText(getApplicationContext(), "OK! I'm performing login.", Toast.LENGTH_SHORT).show();
你可能还想做最后一件事,改变TextInputLayout控件的颜色。默认AppCompact会把它设置成绿色的,但是很有可能这个颜色会和你的颜色主题(color palette)冲突。
谷歌把Design Support Library写的很好。每一个控件的颜色都是直接通过主题颜色绘制的,在 style.xml 中指定。打开它添加colorAccent 到主题以改变表单的颜色。
&style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"&
&item name="colorAccent"&#3498db&/item&
本教程中,我们看到了如何实现新的布局元素TextInputLayout,多亏有了刚刚引入的Design Support Library。
设计范例中,控件的实现需要让用户在输入的过程中不会丢失上下文信息,它是在去年跟Material Design一起被谷歌介绍的。在这之前,没有让开发者将这个控件应用到实际项目中的支持库。现在,如果你的应用有类似数据输入的地方,你终于可以完全遵循material design 了。
版权声明:本文内容由互联网用户自发贡献,本社区不拥有所有权,也不承担相关法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至: 进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。
用云栖社区APP,舒服~
【云栖快讯】浅析混合云和跨地域网络构建实践,分享高性能负载均衡设计,9月21日阿里云专家和你说说网络那些事儿,足不出户看直播,赶紧预约吧!&&
是众安保险针对阿里云用户推出的信息安全综合保险,若因黑客攻击导致用户云服务器上的数据泄露并造成经济损失,众安保险...
专精于业务数据与地理信息融合的大数据可视化,通过图形界面轻松搭建专业的可视化应用, 满足您日常业务监控、调度、会...
立足于对政务信息化的深刻理解,在云计算和大数据技术上持续创新,构筑开放共享、敏捷高效、安全可信的政务云基础架构,...
为您提供简单高效、处理能力可弹性伸缩的计算服务,帮助您快速构建更稳定、安全的应用,提升运维效率,降低 IT 成本...
MaxCompute75折抢购
Loading...如何用&Android&Studio&导入开源项目以及常见错误的解决办法
如果不引入任何第三方库,不做自动化分渠道打包等操作,那可以在完全不了解Gradle的情况下进行Android项目的开发。但如果要想导入Github上的热门项目,必须首先熟悉Gradle。
Gradle是以Groovy为基础,面向java应用,基于DSL语法的自动化构建工具。是google引入,替换ant和maven的新工具,其依赖兼容maven和ivy。
简单来说,Gradle就是Andriod
Studio引入的一种自动构建工程的工具,很好的解决了Android项目的构建。大概能解决以下开发过程中的痛点:
不用把第三方库下载下来。以前用Eclipse必须得把第三方库下载下来,然后在自己的项目中引入那个第三方library才行。但使用Gradle,几行代码就搞定第三方库的依赖,降低了耦合性。
不用手动修改N次代码,把代码打N个包发到N个市场。以前可能需要针对不同的渠道发不同的APK文件包,现在只需要在gradle中的几行代码就能一次生成多个渠道包。具体可参考此文章:。
如果你用AS新建一个项目,那此项目的默认项目结构如图所示,图中打开的文件是TestMe/build.gradle,已经给出了每句话的含义。
图中新建项目名为TestMe,使用了Project的目录结构。此目录下可见以下几个gradle文件,分别是:
TestMe/build.gradle,全局gradle,在这个文件里的设置会在整个项目里通用。
TestMe/app/build.gradle,模块的gradle,仅在app模块通用。
TestMe/settings.gradle,用于指定哪个目录是模块model。里面的内容默认是include
‘:app‘,表示app这个文件夹是一个模块。
而TestMe/app/build.gradle文件内容如图所示,具体解释参见图中注释。
2. 导入MaterialDesignLibrary项目
我们的目标是把MaterialDesignLibrary项目在AS里面成功运行,并在手机上运行成功。
2.1 第一步
首先,用git的clone命令将下载到本地。
2.2 第二步
进入AS,File-&Import
Project,然后找到MaterialDesignLibrary目录,双击该目录下的build.gradle即可导入项目。
2.3 第三步
可以看导入好的Github上的MaterialDesignLibrary项目包含两个module,包括MaterialDesignDemo和一个MaterialDesign。
MaterialDesign的build.gradle文件第一行为:apply plugin:
‘com.android.library‘,表示这是一个Library。
MaterialDesignDemo的build.gradle文件第一行为:apply plugin:
‘com.android.application‘,表示这是一个应用。
他的这个项目使用的是引用本地已有的MaterialDesign库,而本文第三部分要讲的是引用网上中心库的MaterialDesign库。两种方法都可以,但后一种更加方便更常用,第一种方法不太常用。
第二步之后,可能会出现很多错,通常是因为配置问题,这部分详见本文下面的常见错误。&
注意:一定要确保根目录下的setting.gradle里面是include ‘:MaterialDesign‘,
‘:MaterialDesignDemo‘。表示以上两个文件夹都是module。
3. 在自己的项目中引用MaterialDesignLibrary
还是之前的TestMe项目,只需要在TestMe/app/build.gradle中的dependencies中加入compile
‘com.github.navasmdc:MaterialDesign:1.5@aar‘即可,如下:
dependencies {
// 编译libs目录下的所有jar包
compile fileTree(dir: ‘libs‘, include: [‘*.jar‘]) //多个文件
//compile files(‘libs/foo.jar‘)
//单个文件这样写
compile ‘com.android.support:appcompat-v7:22.0.0‘ //编译第三方库
compile ‘com.github.navasmdc:MaterialDesign:1.5@aar‘
4. 常见错误
AS在导入开源的项目或者第三方库的时候经常会出现的错误如下。其实很多都是各种工具的版本问题。
Error:failed to find Build Tools revision
是因为该开源库对应的Build
Tools的版本你的AS里面没有。解决方法是点击他的链接进行下载。或者更改每个model里面的build.gradle文件中的buildToolsVersion
"21.1.1"为本机里面有的Build Tolls版本。
Error:failed to find target android-18 :
/Users/xujin/develop/adt-bundle-mac-x86_64-/sdk
是因为该开源库对应的android
sdk的版本你的机器里面没有。解决方法同上,要么下载,要么改改配置。更改每个model里面的build.gradle文件中的compileSdkVersion
21为本机里面有的sdk版本。
Error:(44, 30) 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7
或更高版本以启用 diamond 运算符)
出错的原因是因为代码中有&List cars = new
ArrayList&&();,java在1.7引入了钻石运算符&&,解决办法有两种。一是更改编译的java
sdk版本,而是将出错代码改为List cars = new ArrayList();
Error:(37) No resource identifier found for attribute ‘checked’
in package ‘com.gc.materialdesign’
是因为第37行的materialdesign:checked="true",命名空间materialdesign里面没有checked属性,改成check即可,代码如下。(之前遇到过,姑且说说。)
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#1E88E5"
materialdesign:check="true"
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。当前位置: →
→ Android开发之EditText属性详解
Android开发之EditText属性详解
& 作者及来源: 无恨星晨 - 博客园 &
&收藏到→_→:
摘要: Android开发之EditText属性详解
"Android开发之EditText属性详解"::
1、edittext输入的文字为密码形式的设置
(1)通过.xml里设置:
&把该edittext设为:android:password="true"&// 以&.&形式显示文本
(2)在代码里设置:
通过设置edittext的settransformationmethod()方法来实现隐藏密码或这显示密码。
edittext.settransformationmethod(passwordtransformationmethod.getinstance());//设置密码为不可见。
2、(1)edittext输入的文字为电话号码
android:phonenumber=&true&&&//输入电话号码
3、edittext字数限制的设置
(1)在.xml中设置:android:maxlength=&50&&
(2)代码中设置: &&
edittext.setfilters(new inputfilter[]{newinputfilter.lengthfilter(100)});
4、edittext设置字体
android:typeface="monospace" //设置字型。字形有:normal, sans, serif,monospace
5、edittext是否可编辑
android:editable // 是否可编辑
6、在edittext中软键盘的调起、关闭
(1)edittext有焦点(focusable为true)阻止输入法弹出
&edittext=(edittext)findviewbyid(r.id.txtbody);
&&&edittext.setontouchlistener(new ontouchlistener(){&&
&&&&&&&&&public boolean ontouch(view v, motionevent event){&
&&&&&&&&&&&&edittext.setinputtype(inputtype.type_null); //关闭软键盘&&&&&
&&&&&&&&&&&&
&&&&&&&&&}
(2)当eidttext无焦点(focusable=false)时阻止输入法弹出
&inputmethodmanager imm =
(inputmethodmanager)getsystemservice(input_method_service);&
&imm.hidesoftinputfromwindow(edittext.getwindowtoken(),0);
(3)调用数字键盘并设置输入类型和键盘为英文
etnumber.setinputtype(inputtype.type_class_number); //调用数字键盘
rledittext.setinputtype(inputtype.type_text_flag_multi_line);//设置输入类型和键盘为英文 或者:android:inputtype="texturi|textmultiline"
(4)android:focusable="false"//键盘永远不会弹出
&activity android:name=".addlinkman"android:windowsoftinputmode="adjustunspecified|statehidden"/&//不自动弹出键盘
//关闭键盘(比如输入结束后执行) inputmethodmanager imm =(inputmethodmanager)getsystemservice(context.input_method_service); imm.hidesoftinputfromwindow(etedittext.getwindowtoken(), 0);
//自动弹出键盘
((inputmethodmanager)getsystemservice(input_method_service)).togglesoftinput(0,inputmethodmanager.hide_not_always);
etedittext.requestfocus();//让edittext获得焦点,但是获得焦点并不会自动弹出键盘
7、android:layout_gravity和android:gravity的区别
(1)android:layout_gravity是本元素对父元素的重力方向。
(2)android:gravity是本元素所有子元素的重力方向。
8、android:padding和android:layout_margin区别
这两个都可以设置边距,但有细微的区别:
(1)android:padding是相对父view的边距
(2)android:layout_margin是相对同一级view的边距
例:linearlayout是水平布局,下面有两个按钮,
(a)如果右边的按钮想距左边的按钮15px,因为这两个按钮是同一级的,应该用android:layout_margin;
(b)如果右边的按钮想距左边的距离为350px,应该用android:padding
9、android:numeric//只接受数字
android:numeric来控制输入的数字类型,一共有三种分别为integer(正整数)、signed(带符号整数,有正负)和decimal(浮点数)。
10、enter键图标的设置
软键盘的enter键默认显示的是&完成&文本,我们知道按enter建表示前置工作已经准备完毕了,要去什么什么啦。比如此文来自: 马开东博客
转载请注明出处 网址:
,在一个搜索中,我们输入要搜索的文本,然后按enter表示要去搜索了,但是默认的enter键显示的是&完成&文本,看着不太合适,不符合搜索的语义,如果能显示&搜索&两个字或者显示一个表示搜索的图标多好。事实证明我们的想法是合理的,android也为我们提供的这样的功能。通过设置android:imeoptions来改变默认的&完成&文本。这里举几个常用的常量值:
(1)actionunspecified未指定,对应常量editorinfo.ime_action_unspecified效果:
(2)actionnone 没有动作,对应常量editorinfo.ime_action_none效果:
(3)actiongo去往,对应常量editorinfo.ime_action_go 效果:
(4)actionsearch 搜索,对应常量editorinfo.ime_action_search效果:&
(5)actionsend 发送,对应常量editorinfo.ime_action_send效果:
(6)actionnext 下一个,对应常量editorinfo.ime_action_next效果:
(7)actiondone 完成,对应常量editorinfo.ime_action_done效果:
11、使用android:imeoptinos可对android自带的软键盘进行一些界面上的设置:
android:imeoptions="flagnoextractui"&//使软键盘不全屏显示,只占用一部分屏幕 同时,这个属性还能控件软键盘右下角按键的显示内容,默认情况下为回车键 android:imeoptions="actionnone"&//输入框右侧不带任何提示 android:imeoptions="actiongo"&&&//右下角按键内容为'开始' android:imeoptions="actionsearch"&//右下角按键为放大镜图片,搜索 android:imeoptions="actionsend"&&&//右下角按键内容为'发送' android:imeoptions="actionnext"&&//右下角按键内容为'下一步' android:imeoptions="actiondone"&//右下角按键内容为'完成'
12、限定edittext能输入数字和字母,并且默认输入为数字,如身份证号码
android:inputtype="number" android:digits="xyzxyz"
13、软键盘的调起导致原来的界面被挤此文来自: 马开东博客
转载请注明出处 网址:
上去,或者导致界面下面的tab导航被挤上去,解决方法如下
解决方法:
使用manifest中的activity的android:windowsoftinputmode的"adjustpan"属性。
另外注意:有关软键盘的问题可参考android:windowsoftinputmode中属性。
14、edittext光标详解 edittext.requestfocusfromtouch();//让光标放入到点击位置。 edittext.requestfocus();//默认方式获得焦点edittext editor = (edittext)getcurrentview();//光标处插入 int cursor = editor.getselectionstart(); editor.gettext().insert(cursor,delta);
让光标移到末端(这样文字就会向前显示) edittext et = ... string text = "text"; et.settext(text); et.setselection(text.length());
android:cursorvisible="false" 隐藏光标
android:background="#"//不要背景&
android - 的输入法控制和默认焦点设置
在开发中,必不可少的会使用到(edittext)来进行数据录入,也就会需要对输入法进行一些控制。
先看下layout定义文件中的和输入法有关的属性:
android:inputtype
指定输入法的类型,int类型,可以用|选择多个。取值可以参考:android.text.inputtype类。取值包括:text,
texturi, phone,number,等。
android:imeoptions
指定输入法窗口中的回车键的功能,可选值为normal,
actionnext,actiondone,actionsearch等。部分输入法对此的支持可能不够好。
下面的layout定义文件举了一些例子说明inputtype和imeoptions的使用。
android:id="@+id/textnormal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="normal
android:inputtype="text"
android:imeoptions="actionnext"
android:id="@+id/textinteger"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="integer
android:inputtype="number"
android:imeoptions="actionnext"
android:id="@+id/textphone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="phone
android:inputtype="phone"
android:imeoptions="actionnext"
android:id="@+id/textemail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="email"
android:imeoptions="actionsend"
android:inputtype="textemailaddress"
android:id="@+id/textsite"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="web
android:imeoptions="actiondone"
android:inputtype="texturi"
有时候也要对intent的默认焦点进行设置,不至于在intent跳转的时候默认焦点(光标)在edittext上,导致进入intent就打开输入法,影响界面美观。
默认焦点的顺序是:从上倒下
从左到右第一个可以输入的控件作为焦点
可以使用:
button.setfocusable(true);
button.requestfocus();
button.setfocusableintouchmode(true);
在edittext前面放置一个看不到的linearlayout,让他率先获取焦点:
&linearlayout
android:focusable="true"
android:focusableintouchmode="true"
android:layout_width="0px"
android:layout_height="0px"/&android edittext 属性汇总
android edittext 属性汇总
android:layout_gravity="center_vertical" 设置控件显示的位置:默认top,这里居中显示,还有bottom 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:capitalize = "characters" 以大写字母写
android:textalign="center" edittext没有这个属性,但textview有 android:textcolorhighlight="#cccccc" 被选中文字的底色,默认为蓝色
android:textcolorhint="#ffff00" 设置提示信息文字的颜色,默认为灰色 android:textscalex="1.5" 控制字与字之间的间距
android:typeface="monospace" 字型,normal, sans, serif, monospace android:background="@null" 空间背景,这里没有,指透明
android:layout_weight="1" 权重,控制控件之间的地位,在控制控件显示的大小时蛮有用的。
android:textappearance="?android:attr/textappearancelargeinverse" 文字外观,这里引用的是系统自带的一个外观,?表示系统是否有这种外观,否则使用默认的外观。不知道这样理解对不对? 通过edittext的layout xml文件中的相关属性来实现:
1. 密码框属性 android:password="true" 这条可以让edittext显示的内容自动为星号,输入时内容会在1秒内变成*字样。
2. 纯数字 android:numeric="true" 这条可以让输入法搜索此文相关文章:此文来自: 马开东博客
网址: 站长QQ
Android开发之EditText属性详解_博客园相关文章
博客园_总排行榜
博客园_最新
博客园_月排行榜
博客园_周排行榜
博客园_日排行榜

我要回帖

更多关于 design和text切换按钮 的文章

 

随机推荐