仿知乎app登录界面(Material Design设计框架拿来就用的TexnInputLayout)
在我脑子里还没有Material Design这种概念,就我个人而言,PC端应用扁平化设计必须成为首选,手当其冲的两款即时通讯旺旺和QQ早就完成UI扁平化的更新,然而客户端扁平化的设计本身就存在天生的缺陷,手指和鼠标箭头最大的区别是在于前者有温度和感觉的,这时候Material Design应运而生。
关于Material Design,材料设计你大概已经知道了,它介于拟物于扁平(qq,旺旺PC端应用)之间的设计。Material Design有着自己的目标,不仅仅为了好看整体而已,它要让不同设备的屏幕表现出一直、美观的视觉体验以及交互。主要包括的控件有TabLayout、TextInputLayout、SwitchCompat、Card、SnackBar、BottomSheet、Shadows、FloatingActionButton、RecycleView、NavigationView....
之前知乎app的登录界面好像是这个效果。这里我们就来体验一下TextInputLayout的具体效果:最终的效果图(在真机上有一定差距)如下:
这篇文章主要分为以下几个部分
- 首先通过nuget引入xamarin.android.design.widget
- TextInputLayout布局
- TextInputLayout文本框样式修改
- 通过单击事件验证TextInputLayout文本框错误的提示
nuget引入xamarin.android.design.widget
TextInputLayout布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_primary">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="30dp"
android:paddingLeft="40dp"
android:paddingRight="40dp">
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="50dp"
android:gravity="center"
android:text="登录"
android:textSize="40sp"
android:textColor="@color/color_white"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/userNameContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tvTitle"
android:layout_marginTop="4dp">
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/userName"
android:inputType="textPassword"
android:textColor="@color/color_white"
android:textColorHint="@color/color_dedede"
android:hint="userName"/>
</android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout
android:id="@+id/passWordContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_below="@id/userNameContainer">
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/passWord"
android:inputType="textPassword"
android:textColor="@color/color_white"
android:hint="Password"/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/MyButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/passWordContainer"
android:text="@string/Hello"/>
</RelativeLayout>
</LinearLayout>
注意的是TextInputLayout内只能放TextView控件,并且不能单独使用,只用布局就可以实现这种获取焦点hint上滑的动画效果。当然这和你的界面要求还是有一定差距的,所以这TextView的一些样式还需要自定义。
TextInputLayout文本框样式修改
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">#ffffff</item>
<item name="android:textColorHint">@color/color_dedede</item>
<item name="colorControlNormal">@color/color_dedede</item>
<item name="colorControlActivated">@color/color_white</item>
</style>
?colorAccent 是哪里的颜色?是系统特定内容的颜色,类似的颜色statusBarColor、windowBackground,看这张图你就明白了
文本没有获取焦点的文字颜色:android:textColorHint
通过事件验证TextInputLayout文本框错误的提示
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
TextInputLayout userName = FindViewById<TextInputLayout>(Resource.Id.userNameContainer);
TextInputLayout passWord= FindViewById<TextInputLayout>(Resource.Id.passWordContainer);
passWord.EditText.TextChanged += (s, e) =>
{
System.Diagnostics.Debug.WriteLine(e.Start);
System.Diagnostics.Debug.WriteLine(e.Text);
if (e.Start > 8)
{
passWord.ErrorEnabled = true;
passWord.Error = "密码不能大于8位";
}
else
{
passWord.ErrorEnabled = false;
}
};
userName.EditText.FocusChange += (s, e) =>
{
if (!e.HasFocus)
{
if (ValidateTel(userName.EditText.Text))
{
userName.ErrorEnabled = false;
}
else
{
userName.ErrorEnabled = true;
userName.Error = "userName不正确";
}
}
};
}
private bool ValidateTel(string tel)
{
string matchReg = "^1[3|4|5|7|8][0-9]{9}$";
return System.Text.RegularExpressions.Regex.IsMatch(tel,matchReg);
}
虽然你也可以在TextInputLayout自带的属性带实现这个效果,那样太死板了。如果你真的要写在Xml文件里你可以这样的,首先在根布局中添加 xmlns:app="http://schemas.android.com/apk/res-auto" 使用自带控件的属性。常见的属性:
app:counterEnabled="true"
app:counterMaxLength="4"
作者:张林
标题:仿知乎app登录界面(Material Design设计框架拿来就用TexnInputLayout
原文地址:http : //blog.csdn.net/kebi007/article/details/70470754
转载随意注明出处
仿知乎app登录界面(Material Design设计框架拿来就用的TexnInputLayout)的更多相关文章
- Android Material Design-Creating Apps with Material Design(用 Material Design设计App)-(零)
转载请注明出处:http://blog.csdn.net/bbld_/article/details/40400031 翻译自:http://developer.android.com/trainin ...
- 超实用!9个目前流行的MATERIAL DESIGN前端框架
http://www.uisdc.com/material-design-frameworks-top-9 谷歌推出的Material Design风格已见有一些APP UI采用,视觉和交互体验都很棒 ...
- 轻量级 Material Design 前端框架 MDUI (纯html,css,与css框架跟react vue不冲突)
MDUI 是一个轻量级的 Material Design 前端框架,对照着 Material Design 文档进行开发,争取 1:1 实现 Material Design 中的组件. 多主题支持 M ...
- 用户登录(Material Design + Data-Binding + MVP架构模式)实现
转载请注明出处: http://www.cnblogs.com/cnwutianhao/p/6772759.html MVP架构模式 大家都不陌生,Google 也给出过相应的参考 Sample, 但 ...
- Android 使用Toolbar+DrawerLayout快速实现仿“知乎APP”侧滑导航效果
在以前,做策划导航的时候,最常用的组件便是SlidingMenu了,当初第一次用它的时候觉得那个惊艳啊,体验可以说是非常棒. 后来,Android自己推出了一个可以实现策划导航的组件DrawerLay ...
- Android 仿 窗帘效果 和 登录界面拖动效果 (Scroller类的应用) 附 2个DEMO及源码
在android学习中,动作交互是软件中重要的一部分,其中的Scroller就是提供了拖动效果的类,在网上,比如说一些Launcher实现滑屏都可以通过这个类去实现.下面要说的就是上次Scroller ...
- Android 仿 窗帘效果 和 登录界面拖动效果 (Scroller类的应用) 附 2个DEMO及源代码
在android学习中,动作交互是软件中重要的一部分.当中的Scroller就是提供了拖动效果的类,在网上.比方说一些Launcher实现滑屏都能够通过这个类去实现.以下要说的就是上次Scroller ...
- Material UI – Material Design CSS 框架
Material Design 是谷歌推出的全新的设计理念,采用大胆的色彩.流畅的动画播放,以及卡片式的简洁设计.Material Design 风格的设计拥有干净的排版和简单的布局,容易理解,内容才 ...
- .Net语言 APP开发平台——Smobiler学习日志:仿12306的APP登陆界面
最前面的话:Smobiler是一个在VS环境中使用.Net语言来开发APP的开发平台,也许比Xamarin更方便 一.目标样式 我们要实现上图中的效果,需要如下的操作: 1.从工具栏上的”Smobil ...
随机推荐
- eclipse中Maven工程使用Tomcat7以上插件
Maven中使用tomcat:run命令默认是使用Tomcat6的版本, 现在要用到Tomcat7以上的版本,在eclipse的Maven工程中配置如下 第一步:在项目的pom里面加入如下配置: 官网 ...
- linux文件、目录
user用户 group用户组 others其他人用户信息保存在/etc/passwd [root@iZ25het8xn8Z ~]# ls -altotal 56dr-xr-x---. 3 root ...
- 深入浅出多线程——ReentrantLock (二)
深入浅出多线程——ReentrantLock (一)文章中介绍了该类的基本使用,以及在源码的角度分析lock().unlock()方法.这次打算在此基础上介绍另一个极为重要的方法newConditio ...
- 推荐一款基于bootstrap的漂亮的前端模板—inspinia_admin
首先给出Demo网址:http://cn.inspinia.cn inspinia admin 最新版 bootstrap 完全响应式后台管理模板,采用扁平化设计.使用Bootstrap 3+ Fra ...
- shell,bash,zsh,console,terminal到底是什么意思,它们之间又是什么关系?
原文链接 终端(terminal,或者叫物理终端):是一种设备,不是一个程序,一般说的就是能提供命令行用户界面的设备,典型的是屏幕和键盘,或其他的一些物理终端.虚拟终端:屏幕和键盘只是一个终端,可能不 ...
- 前端测试框架Jest系列教程 -- Asynchronous(测试异步代码)
写在前面: 在JavaScript代码中,异步运行是很常见的.当你有异步运行的代码时,Jest需要知道它测试的代码何时完成,然后才能继续进行另一个测试.Jest提供了几种方法来处理这个问题. 测试异步 ...
- 前端自动化测试漫长路之——Selenium初探
引言 最近想解决前端开发或测试中的两个问题:一是界面UI的布局适配,能否在测试的过程中,通过命令操作真机打开相应页面然后截屏,通过对图片识别分类,发现有问题的图片,然后及时修复:二是页面性能分析,很多 ...
- 原生Js实现拖拽(适用于pc和移动端)
效果: HTML和CSS部分 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- YiShop_最全微信营销涨粉技巧
在我们开始推广企业订阅号之前,我们必须思考微信营销策略,客户通过微信可以获得什么?企业通过微信可以得到什么?微分销专家建议企业微信定位为互动.服务工具,因为获取一个粉丝很难,可是失去一个粉丝,却是一件 ...
- NGUI_PopupList
八.PopuList下拉菜单 1.使用Populist的规律: (1).有一系列选项需要玩家做出选择,这些选项是有限多个的. (2).这些选项玩家必须选择一个,也只能选择一个. (3).这些选项如果全 ...