第十五篇-EditText做简单的登录框
TextView和EditText的简单应用。
MainActivity.java
package com.example.aimee.edittexttest; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.layout);
}
}
layout.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/phonenumber"
android:textSize="24sp"/> <EditText
android:layout_width="196dp"
android:layout_height="wrap_content"
android:background="@drawable/edit_bg"//设置编辑框背景为矩形框
android:hint="@string/phone"
android:imeOptions="actionGo"
android:inputType="phone"
android:maxLength="40"
android:textColorHint="#FFFF0000"
android:textSize="24sp"/> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/passwordtext"
android:textSize="24sp"
android:layout_marginTop="30dp" /> <EditText
android:layout_width="196dp"
android:layout_height="wrap_content"
android:background="@drawable/edit_bg"
android:hint="@string/password"
android:imeOptions="actionSearch"
android:inputType="textPassword"
android:maxLength="40"
android:textColorHint="#FF000000"
android:textSize="24sp" /> </LinearLayout>
输入密码会用点来代替。
edit_bg.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#EFEFEF"/>
<corners android:radius="3dip"/>
<stroke
android:width="0.5px"
android:color="#505050"/>
</shape> </item>
</layer-list>
属性的含义:
android:imeOptions="flagNoExtractUi" //使软键盘不全屏显示,只占用一部分屏幕 同时,
这个属性还能控件软键盘右下角按键的显示内容,默认情况下为回车键
android:imeOptions="actionNone" //输入框右侧不带任何提示
android:imeOptions="actionGo" //右下角按键内容为'开始'
android:imeOptions="actionSearch" //右下角按键为放大镜图片,搜索
android:imeOptions="actionSend" //右下角按键内容为'发送'
android:imeOptions="actionNext" //右下角按键内容为'下一步' 或者下一项
android:imeOptions="actionDone" //右下角按键内容为'完成'
注意:如果设置了 键盘没有变化 那么需要单独加一些其他的属性 配合使用
xml中 属性设置:
1 将singleLine设置为true
2 将inputType设置为text
java代码设置
editText.setInputType(EditorInfo.TYPE_CLASS_TEXT);
editText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
android:ems = "10" 的含义 :
指的是将对应的控件宽度设为10个字符的宽度。当设置该属性后,一行中最大只能显示设置的宽度。
如果想要实现用户名和编辑框在同一行,密码和编辑框也在同一行。
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"> <TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="23dp"
android:text="用户名" /> <EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:background="@drawable/edit_bg"
android:ems="10"
android:textSize="23dp"
android:hint="请输入用户名"
android:inputType="textPersonName" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="23dp"
android:text="密码" /> <EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginVertical="20dp"
android:background="@drawable/edit_bg"
android:ems="10"
android:textSize="23dp"
android:hint="请输入密码"
android:inputType="textPassword" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"> <Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录" /> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:text="取消" />
</LinearLayout>
</LinearLayout>
这是设置了3个LinearLayout为垂直排布,每个LinearLayout里面是水平排布。
第十五篇-EditText做简单的登录框的更多相关文章
- 跟我学SpringCloud | 第十五篇:微服务利剑之APM平台(一)Skywalking
目录 SpringCloud系列教程 | 第十五篇:微服务利剑之APM平台(一)Skywalking 1. Skywalking概述 2. Skywalking主要功能 3. Skywalking主要 ...
- Egret入门学习日记 --- 第十五篇(书中 6.1~6.9节 内容)
第十五篇(书中 6.1~6.9节 内容) 好的,昨天完成了第五章. 今天来看第六章. 总结重点: 1.如何对组件进行分组? 跟着做: 重点1:如何对组件进行分组? 首先,选中你想要组合的组件. 然后点 ...
- Python之路【第十五篇】:Web框架
Python之路[第十五篇]:Web框架 Web框架本质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. 1 2 3 4 5 6 ...
- 第十五篇 Integration Services:SSIS参数
本篇文章是Integration Services系列的第十五篇,详细内容请参考原文. 简介在前一篇,我们使用SSDT-BI将第一个SSIS项目My_First_SSIS_Project升级/转换到S ...
- 【译】第十五篇 Integration Services:SSIS参数
本篇文章是Integration Services系列的第十五篇,详细内容请参考原文. 简介在前一篇,我们使用SSDT-BI将第一个SSIS项目My_First_SSIS_Project升级/转换到S ...
- 解剖SQLSERVER 第十五篇 SQLSERVER存储过程的源文本存放在哪里?(译)
解剖SQLSERVER 第十五篇 SQLSERVER存储过程的源文本存放在哪里?(译) http://improve.dk/where-does-sql-server-store-the-sourc ...
- 【python笔记】Qt+云函数 实现简单的登录框制作
[python笔记]Qt+云函数 实现简单的登录框制作 备注:前置条件:QtDesigner.pycharm.PyQt5.配置好的云函数(百度的叫函数计算CFC,用来充当一个简陋的服务器,主要是免费) ...
- Android UI开发第三十五篇——AppCompat实现Action Bar
每一位Android开发者对Action Bar这种设计都不陌生了,毕竟它已经发布了至少两年了.Android团队发布Action Bar设计规范时同时放出了ActionBar的Api来支持这种设计. ...
- SpringBoot第十五篇:swagger构建优雅文档
作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/11007470.html 版权声明:本文为博主原创文章,转载请附上博文链接! 引言 前面的十四 ...
随机推荐
- Airflow 使用随笔(内含 TimeZone 和 Backfill 等的详解)
其实怎么部署 airflow 又哪些特性,然后功能又是如何全面都可以在 Reference 的文章里面找到,都不是重点这里就不赘述了. 这里重点谈一下我在部署完成仔细阅读文档之后觉得可以总结的一些东 ...
- vscode git設置
1.git官网https://git-scm.com/download/win 链接下载:64-bit Git for Windows Setup,不要下载Portable,体积太大了: 如果git官 ...
- 由 POST 400 错误拔出来的萝卜
缘起 前段时间遇到扫描问题,好不容易拿到了扫描出来的数据,结果调用接口时弹了个 400(Bad request) 给我,匆匆找了点资料修补上线后,忐忑的心也可以安分点.然后,顺着这个 400 的萝卜, ...
- 今日头条移动app广告激活数据API对接完整Java代码实现供大家参考》》》项目随记
这是自毕业后的第一篇博客,希望自己今后能养成写博客的一个好习惯.最近公司为了加速APP推广,采取在外部平台(如:今日头条)进行广告投放的方式,进行用户引流.因此我们需要对广告的激活数据进行一个检测,跟 ...
- poj2100(尺取法)
题意:选取一系列数,使得这些数的平方和等于n: 解题思路:尺取法扫一遍: #include<iostream> #include<algorithm> using namesp ...
- [离散时间信号处理学习笔记] 10. z变换与LTI系统
我们前面讨论了z变换,其实也是为了利用z变换分析LTI系统. 利用z变换得到LTI系统的单位脉冲响应 对于用差分方程描述的LTI系统而言,z变换将十分有用.有如下形式的差分方程: $\displays ...
- js弹框的3种方法
js的三种弹框的方法 1.第一种 : alert("1"); 2.第二种 : window.open("Tests2.html"); var r = con ...
- Luogu5289 十二省联考2019字符串问题(后缀数组+拓扑排序+线段树/主席树/KDTree)
先考虑80分做法,即满足A串长度均不小于B串,容易发现每个B串对应的所有A串在后缀数组上都是一段连续区间,线段树优化连边然后判环求最长链即可.场上就写了这个. 100分也没有什么本质区别,没有A串长度 ...
- Chrome不安装插件实现页面长截图
1.打开需要截图的页面,按F12进入审查模式 或直接在页面右击鼠标右键-检查,打开如下窗口 2.在控制台中按下 ctrl+shift+p,弹出如下输入框 3.输入screen进行模糊查找,选择“Ca ...
- 洛谷P2045 K方格取数(算竞进阶习题)
费用流 又是一道网络流的模型,对于这种费用与经过次数有关的边,我们经常把边拆成多条,比如这个题,第一次费用是x,第二次是0,我们就可以先把点拆成入点和出点,入点和出点又连两条边,第一条容量为1,费用为 ...