Android Design Library 浅应用

</pre>android 的MD设计规范让我们认识到android其实也可以像ISO一样炫酷,但是由于android的版本太多,向下兼容难,大部分的MD设计规范只能在android 5.0以后才能用上。<p></p><p>为此谷歌为我们提供了android的MD向下兼容包design架包,这个库里面有很多很炫酷的空间。比较常用的是FloatingActionButton这个空间,MD设计的效果图</p><p><img src="https://img-blog.csdn.net/20151026151429394?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /></p><p></p><pre name="code" class="java"><pre name="code" class="html">    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

这是一个简单的FloatingActionButton的用法,经常用与和Snack结合提示信息
</pre>
<pre name="code" class="html">
TextInputLayout 是另外一个代替或者说是增加edittext的空件,它可以在为输入时候显示提示内容,输入错误可以提示错误。输入时候提示信息不会消失。代码如下:
<pre name="code" class="java">//        final TextInputLayout textinput=(TextInputLayout)findViewById(R.id.textinput);
//        textinput.setHint("请输入用户名");
//        EditText editText=textinput.getEditText();
//        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() > 8) {
//                    textinput.setError("用户名不能超过十位");
//                    textinput.setErrorEnabled(true);
//                } else {
//                    textinput.setErrorEnabled(false);
//                }
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//
//            }
//        });


还有TabLayout这个控件必须学会运用,因为它相比与一般的开源控件使用起来更加简单方便。一般会有ViewPager结合在一起使用:
<pre name="code" class="java"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.houjiawei.designlearning.MainActivity"
    tools:showIn="@layout/activity_main">

    <android.support.design.widget.TabLayout
        android:layout_marginTop="60dp"
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabTextColor="@android:color/holo_blue_light"
        app:tabSelectedTextColor="#ff0000"
        app:tabIndicatorHeight="5dp"
        app:tabMode="scrollable"
        ></android.support.design.widget.TabLayout>


    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.v4.view.ViewPager>


</LinearLayout>

在Acitvity添加标题代码就是:
 tabLayout.addTab(tabLayout.newTab().setText("tab1"));这么简单

最后还有android.support.design.widget.CoordinatorLayout 这个强大的组合控件,效果图如下





xml布局如下:

<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.example.houjiawei.designlearning.CoordinatorActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_coordinator" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值