今天这篇文章应该算是Material Design系列的补充篇,因为这篇文章本来应该放到前面讲的,因为讲的是主题嘛,对于一些状态和颜色的介绍,因为我们一新建一个项目时,系统自带了三个属性的颜色,现在就重点介绍这三个颜色属性的意义和作用。讲明白这个,留着以后讲别的用。

最常用的三个颜色属性

  • colorPrimary
  • colorPrimaryDark
  • colorAccent

这三个分别代表什么意思呢?

  • colorPrimaryDark 是状态栏底色
  • colorPrimary 如果你不手动自己去修改toolbar背景色的话,它就是默认的toolbar背景色
  • colorAccent 各控制元件(比如:checkbox、switch 或是 radio) 被勾选 (checked) 或是选定 (selected) 的颜色

文字描述可能还不是很直观,来看张图,如下:

其他属性相关介绍

  • navigationBarColor 导航栏的背景色,但只能用在 API Level 21 以上的版本,也就是5.0以上才可以
  • windowBackground App 的背景色
  • colorControlNormal 这个也只能在API21以上才能用各控制元件的预设颜色和colorAccent正好对应

在Style上设置

以上的颜色属性均是在 style 的属性中设置。如下:

关于这些颜色的属性介绍就到这里了,相信大家应该都明白了。要是光讲这些文章有点短,不太充实,所以今天我们再补充两个非常简单的 Material Design 风格的控件,可能大家都知道了,知道的就不用看了哈,略过就好。

TextInputLayout

TextInputLayout继承LinearLayout,因此我们需要将EditView包含在TextInputLayout之内才可以使用,言外之意:TextInputLayout不能单独使用。里面可以包含一个且只能有一个EditText,与传统的EditText不同,在输入时EditText的hint提示文字会滑到上方,在用户输入的同时提示用户当前要输入的是什么,同时还可以设置输入错误的提示信息。

代码布局如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<android.support.design.widget.TextInputLayout
android:id="@+id/email_textlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="35dp"
> <EditText
android:id="@+id/email_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入你的邮箱"
android:inputType="textEmailAddress"
android:textColor="@color/text_color"/> </android.support.design.widget.TextInputLayout>

TextInputLayout常用的方法有如下:

  • setHint():设置提示语。
  • getEditText():得到TextInputLayout中的EditView控件。
  • setErrorEnabled():设置是否可以显示错误信息。
  • setError():设置当用户输入错误时弹出的错误信息。

特别注意:TextInputLayout不能单独使用,必须包裹EditView组件,且只能一个,设置错误提示信息时一定要先setErrorEnabled(true);再设置setError()。

TextInputEditText

TextInputEditText和TextInputLayout类似,Design包还有一个组件TextInputEditText,它继承了AppCompatEditText,可以在右侧显示出错误信息的小弹窗提示。用法和TextInputEditText类似,而且不用设置错误信息消除,重新在TextInputEditText输出会自动取消,非常的灵活和人性化。

用法很简单:

1
2
3
4
5
6
7
8
9
<android.support.design.widget.TextInputEditText
android:id="@+id/pwd_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:hint="请输入密码"
android:inputType="textEmailAddress"
android:textColor="@color/text_color"/>

效果图

到这里今天的内容就讲完了,Material Design系列其实还没有完,今天讲了主题样式,下次就有可能讲根据主题样式设置夜间模式,还有以后的转场动画等内容。这个系列可能有些基础,但是众口难调还请大家理解,会的同学可以略过,不会的就好好学习。总之,都是为了大家更进一步。重口难调,还请大家理解。

demo的github地址:https://github.com/loonggg/MaterialDesignDemo 去star吧,我会慢慢完善的。

Android Material Design系列之主题样式介绍说明的更多相关文章

  1. Android Material Design 系列之 SnackBar详解

    SnackBar是google Material Design提供的一种轻量级反馈组件.支持从布局的底部显示一个简洁的提示信息,支持手动滑动取消操作,同时在同一个时间内只能显示一个SnackBar. ...

  2. Android Material Design 兼容库的使用

    Android Material Design 兼容库的使用 mecury 前言:近来学习了Android Material Design 兼容库,为了把这个弄懂,才有了这篇博客,这里先推荐两篇博客: ...

  3. Android Material Design Ripple Effect在Android5.0(SDK=21)以下Android版本崩溃问题解决

    Android Material Design Ripple Effect在Android5.0(SDK=21)以下Android版本崩溃问题解决 附录1的Android Ripple Effect水 ...

  4. Android Material Design : Ripple Effect水波波纹荡漾的视觉交互设计

     Android Material Design : Ripple Effect水波波纹荡漾的视觉交互设计 Android Ripple Effect波纹荡漾效果,是Android Materia ...

  5. Android Material Design的FloatingActionButton,Snackbar和CoordinatorLayout

    如果是为了兼容低版本的Android系统,则需要引用Android Material Design的扩展支持库,我在之前的一篇文章张,较为详细的说明了如何导入Android Material Desi ...

  6. MaterialEditText——Android Material Design EditText控件

    MaterialEditText是Android Material Design EditText控件.可以定制浮动标签.主要颜色.默认的错误颜色等. 随着 Material Design 的到来, ...

  7. Android Material Design控件学习(三)——使用TextInputLayout实现酷市场登录效果

    前言 前两次,我们学习了 Android Material Design控件学习(一)--TabLayout的用法 Android Material Design控件学习(二)--Navigation ...

  8. Material Design系列第四篇——Defining Shadows and Clipping Views

    Defining Shadows and Clipping Views This lesson teaches you to Assign Elevation to Your Views Custom ...

  9. Android Material Design之Toolbar与Palette

    转:http://blog.csdn.net/jdsjlzx/article/details/41441083 前言 我们都知道Marterial Design是Google推出的全新UI设计规范,如 ...

随机推荐

  1. Mac OS使用brew安装memcached

    1.查看安装信息 brew info memcached 显示如下: memcached: stable 1.5.9 (bottled) High performance, distributed m ...

  2. poj1111(单身快乐)

                                                                                                         ...

  3. c#之线程同步--轻量级同步 Interlocked

    轻量级同步 Interlock 为什么说它是轻量级呢?因为它仅对整形数据(即int类型,long也行)进行同步. 如果你学过操作系统里面的PV操作(即信号量),那么你对它已经了解了一般.它实现的正是如 ...

  4. X-UA-Compatible设置IE浏览器兼容模式

    文件兼容性用来告诉IE,让它如何来编译你的网页. 指定 文件兼容性模式 以下是指定为Emulate IE7 mode 兼容性范例. <html> <head> <!-- ...

  5. 微信公众平台OAuth2.0网页授权

    微信公众平台最近新推出微信认证,认证后可以获得高级接口权限,其中一个是OAuth2.0网页授权,很多朋友在使用这个的时候失败了或者无法理解其内容,希望我出个教程详细讲解一下,于是便有了这篇文章. 一. ...

  6. mysql数据库无法插入中文字符

    分析原因:这是因为之前修改了数据库的编码,但数据表的编码却没有跟着改变导致的. 安装mysql 时,使用的是latin编码(随后修改为utf8).建的数据表是在latin编码下建立的.而jsp页面使用 ...

  7. BZOJ2121 字符串游戏 【dp】

    题目链接 BZOJ2121 题解 dp怎么那么神呐QAQ 我们要求出最小字符串长度 我们设一个\(dp[i]\)表示前\(i\)个字符最后所形成的最短字符串长度 对于第\(i\)个字符,要么保留,就是 ...

  8. 序列(seq)

    序列(seq) 题目描述 给定 N,A,BN,A,B,构造一个长度为 NN 的排列,使得: 排列长度为 N: 最长上升子序列长度为 A: 最长下降子序列长度为 B. 我们有 SPJ,有解任意给出一组, ...

  9. This dependency was not found: * !!vue-style-loader!css-loader? 解决方案

    但是当你新建一个vue项目时,需要重新安装stylus,否则报错: This dependency was not found: * !!vue-style-loader!css-loader?{&q ...

  10. git refs 详解

    https://blog.csdn.net/taiyangdao/article/details/52766424 http://www.chenchunyong.com/2017/01/06/git ...