Material Design实现的美观的登录界面

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

官方介绍学习:https://material.google.com/ 英文版基于Material Design的登录界面:http://sourcey.com/beautiful-android-login-and-signup-screens-with-material-design/ 翻译版基于Material Design的登录界面:https://gold.xitu.io/entry/573bb4b6df0eea005e758f0b

Material Design Library

例子中采用了Material Design的库的控件,但是具体使用细节没有写出来,容易遇到很多问题。

Bug: Error inflating class android.support.design.widget.TextInputLayout :添加完xml后,运行时报错。

解决方法: 1.在module的gradle中添加依赖

   compile 'com.android.support:appcompat-v7:24.0.0'
   compile 'com.android.support:design:24.0.0'

并且:修改manifest文件中Application标签下的theme:

   android:theme="@style/Theme.AppCompat"> 

知识梳理:

  1. TextInputLayout是继承于LinearLayout的容器,作用于TextView。而且,跟ScrollView一样,只能包裹一个子节点。它的效果是让Textview中的hint内容悬浮在编辑框之上,而普通textview中的hint则会被覆盖。是Android 5.0以后新加的库的控件(Android Design Support Library)。因此,需要将其library导入到项目中。所以,这就是为什么第一段代码要加入的原因。

  2. Theme.AppCompat Vs 普通版 AppTheme:在Android 4.0之前的Android,可以说是没有设计可言,也就是普通版AppTheme了。在4.0之后,推出了Android Design,界面有所改善,在程序实现上相应的是Holo风格(Theme.Holo.Light、Theme.Holo.Light.DarkActionBar)。为了让4.0之前的版本也兼容,就需要引入v7包, 并能使用其对应兼容的Theme.AppCompat.Light、Theme.AppCompat.Light.DarkActionBar ;而Android 5.0推出了Material Design,为了兼容,也需要引入v7包, 并能够使用其相对应兼容的Material Design Theme:Theme.AppCompat.Light、Theme.AppCompat.Light.DarkActionBar。这就是为什么第二段代码需要加入。

Butter Knife Framework

Butter Knife框架是专门为Android View设计的绑定注解

Bug:The import butterknife.InjectView cannot be resolved:

解决方法:

step1:添加库依赖:

1.在Project的build.gradle中添加:

    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'  

2.在Module的build.gradle中添加:

  • 在代码顶部添加:on the top of the code!!!!
	apply plugin: 'com.android.application'
	apply plugin: 'android-apt'
  • 在依赖中添加:
    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'

    //for the butterknife
    compile 'com.jakewharton:butterknife:8.0.1'
    apt 'com.jakewharton:butterknife-compiler:8.0.1'
	}

step2:删除 import butterknife.InjectView,在MainActivity中添加代码:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }

知识梳理:

Butter Knife就是取代findViewById这样的,使用 @Bind注解并传入一个View ID,Butter Knife 就可以找到并且自动地对你的布局中的View进行转换并绑定到类成员上。相比与缓慢的反射机制,Butter Knife的代码是生成的,因此不必担心注解的性能问题。调用bind来生成这些代码,可以查看或调试这些代码。bug出现是因为例子中的注入方式是早些版本的,最新版本的应该按照http://jakewharton.github.io/butterknife/,以及注解文档:http://jakewharton.github.io/butterknife/javadoc/

转载于:https://my.oschina.net/LaVictoria/blog/718641

你可能感兴趣的:(Material Design实现的美观的登录界面)