zoukankan      html  css  js  c++  java
  • Android Design TextinputLayout

    使用该布局 需要在build.gradle中的dependencies块中添加两个依赖来向下兼容

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.1.0'
        compile 'com.android.support:design:23.1.0'
    }
    <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:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.example.alan.blogs.LoginActivity"
        tools:showIn="@layout/activity_login"
        android:orientation="vertical">
    
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/email_TextInputLayout"
            android:layout_marginTop="32dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            >
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="@string/emailHint"
                android:ems="10"
                android:id="@+id/edit_email" />
           </android.support.design.widget.TextInputLayout>
    
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/password_TextInputLayout">
            <EditText
                android:inputType="textPassword"
                android:id="@+id/edit_password"
                android:hint="@string/passwordHint"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />
        </android.support.design.widget.TextInputLayout>
        <Button
            android:layout_marginTop="16dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="@string/login"
            android:textColor="@color/white"
            android:background="@xml/ripple"
            />
    </LinearLayout>
    public void init(){
            this.emailInputLayout=(TextInputLayout)findViewById(R.id.email_TextInputLayout);
            this.passwordInputLayout=(TextInputLayout)findViewById(R.id.password_TextInputLayout);
           
            final EditText emailEditText=emailInputLayout.getEditText();
            EditText passwordEditText=passwordInputLayout.getEditText();
    //        emailInputLayout.setHint("请输入Email");
    //        passwordInputLayout.setHint("输入密码");                //也可以在editText中设置Hint InputLayput会自动获取该Hint
            emailEditText.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) {
    
                }
    
                @Override
                public void afterTextChanged(Editable s) {
                    if(emailEditText.getText().toString().contains("@")==false){                    emailInputLayout.setErrorEnabled(true);                      emailInputLayout.setError("请输入正确的Email地址");                }else {
                        emailInputLayout.setErrorEnabled(false);
                    }
                }
            });
        }
  • 相关阅读:
    [ASP.NET] Session 一些比较详细的知识(转自:http://blog.csdn.net/zhoufoxcn/archive/2006/11/08/1373685.aspx)
    ASP.NET2.0服务器控件之Render方法 (作者: 金属边缘 出处: 天极开发 )
    [Tip: word pdf] Word Save As PDF
    [Tip: Visual Studio]创建键盘快捷方式速查表
    [Tip: iShare Site] Move file/folder on iShare Site
    google的C++单元测试框架gtest
    XP and Win7 双系统安装教程
    Tip:How to Compact a PST File to Reduce Its Size in Outlook
    [Tip: Perforce]ModTime
    [Tool: fast copy cmd]ROBOCOPY
  • 原文地址:https://www.cnblogs.com/zzw1994/p/5238955.html
Copyright © 2011-2022 走看看