Android Design Support Library 兼容库使用详解

Android Design Support Library 介绍
常规控件的使用介绍
符合 MD 设计的菜单控件
具有过渡动画效果的布局Layout

Android Design Support Library 介绍

主要介绍 Android Design Support Library 的来历,以及Android Design Support Library开发的所需环境

Material Design几个要素

  • 扁平化、简洁
  • 水波反馈
  • 良好体验的过渡动画
  • 材料空间位置的直观变化

Android官方博客在IO大会释出兼容库-Android Design Support Library
MD的时代来临了! 详细介绍

如何使用?一句话搞定!

Android Design Support Library 兼容库的使用前提是下载Android Support Library(更新最新的Support Library,确保更新的Android Support Library是处于22.2以上的版本
这里写图片描述

使用Android Studio创建一个新的项目

在build.gradle中添加 compile ‘com.android.support:design:23.2.1’(以下载的Support Library版本一致)
这里写图片描述
添加完后重新编译一下 Sync Now


或者用工具添加
项目右键—–>Open Module Settings
这里写图片描述

在layout布局中输入android.support是如下提示说明Design Support Library引入成功了
这里写图片描述


如果使用的开发工具是eclipse那么需要将Design Support Library引入到工作空间中
这里写图片描述

引入后修改一下sdk的版本以及引用库 Support-v7
这里写图片描述
上面还应该将Is Library勾选上让它作为一个Library库存在

注:android-support-v7-appcompat是提前引入到工作空间中的library,该library的sdk版本必须与安装Android Support Library版本一致

在eclipse中新建工程并引入design和Support-v7库
这里写图片描述

此时Android Design Support Library的开发环境已经搭建好了,我们就可以将Design Support Library的控件在eclipse中使用了

常规控件的使用介绍

主要讲解 Floating Action Button 、Floating labels for editing text、Snackbar的基本使用方法

常规控件的使用介绍

  • Floating Action Button-浮动的圆形按钮
  • Floating labels for editing text –完美体验的优化版EditText
  • Snackbar-可操作的提示框

在布局文件中使用FloatingActionButton控件

<android.support.design.widget.FloatingActionButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:src="@mipmap/ic_launcher"
        />

FloatingActionButton有几个特殊的属性需要在布局文件中添加app的声明,下面就可以使用app设置一些特殊属性
app:fabSize有两种的属性mini and normal(default)
app:rippleColor=”#000000” 设置按钮点击时的颜色效果
也可以在代码中设置这些属性的值

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.FloatingActionButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:src="@mipmap/ic_launcher"
        app:backgroundTint="#ff0000"
        app:fabSize="normal"
        app:elevation="5dp"
        app:rippleColor="#000000"
        />

</LinearLayout>

Floating labels for editing text –完美体验的优化版EditText

<android.support.design.widget.TextInputLayout
        android:id="@+id/textInput"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />
    </android.support.design.widget.TextInputLayout>
final TextInputLayout textInputLayout = (TextInputLayout) findViewById(R.id.textInput);
        textInputLayout.setHint("请输入用户名");
        EditText editText = textInputLayout.getEditText();//获取TextInputLayout底下的EditText
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(s.length()>10){
                    textInputLayout.setError("用户名不能超过10位");
                    textInputLayout.setErrorEnabled(true);
                }else{
                    textInputLayout.setErrorEnabled(false);
                }
            }

            
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值