MD风格

1  安卓沉浸式状态栏(如果不成功请看2)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
 
2 首先下载systemBartint.jar包,
 
 

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar.TranslucentDecor">
        <!-- Customize your theme here. -->
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowSoftInputMode">stateAlwaysHidden|adjustPan</item>
        <item name="android:fitsSystemWindows">true</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">false</item>
        <item name="android:screenOrientation">portrait</item>
    </style>

</resources>

private void initState() {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      SystemBarTintManager tintManager = new SystemBarTintManager(this);
      tintManager.setStatusBarTintEnabled(true);
      tintManager.setNavigationBarTintEnabled(false);
      tintManager.setStatusBarTintResource(R.color.head_bg_color);
   }
}
然后再相应地方调用。。
 
 

 只有安卓4.4以上支持。。

2  控件水波纹效果

dependencies {
    compile 'com.github.traex.rippleeffect:library:1.3'
}
 
  <com.andexert.library.RippleView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:rv_alpha="90"
    app:rv_centered="false"
    app:rv_color="#00ffff"
    app:rv_framerate="10"
    app:rv_rippleDuration="400"
    app:rv_ripplePadding="1dp"
    app:rv_type="simpleRipple"
    app:rv_zoom="false"
    app:rv_zoomDuration="150"
    app:rv_zoomScale="1.03"
    >
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:textColor="#ffffff"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Hello World!" />
</com.andexert.library.RippleView>
 
3  TextInputLayout控件的使用
<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/usernameWrapper"
    app:hintTextAppearance="@style/CustomTextInputLayoutAppearance"

<style name="CustomTextInputLayoutAppearance">
    <item name="android:textSize">18sp</item>
    <item name="android:textColor">#03f494</item>
</style>



    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">
    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="密码"
        android:singleLine="true"
        android:ellipsize="start"
        android:textColor="#00ff00"
        android:textColorHint="#009900"
        android:inputType="textPassword"
        android:maxLength="15"
        android:imeOptions="actionDone"

        android:layout_below="@+id/editText"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="62dp" />



</android.support.design.widget.TextInputLayout>
  passwordWrapper.setHint("密码");

    passET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                checkPass();
            }
        }
    });




}
  private boolean checkPass() {
    String  pass = passET.getText().toString();
    if (pass.length() < 6) {
        passwordWrapper.setErrorEnabled(true);
        passwordWrapper.setError("密码少于6位数");
        return false;
    }
    passwordWrapper.setErrorEnabled(false);
    return true;
}
 修改colorAccent属性便可以指定TextInputLayout的标签字体颜色以及EditText的下划线颜色。
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
 <item name="colorAccent">#3498db</item>
</style>

 对用户的输入(即mTextInputLayout.getEditText().getText().toString())在后台进行验证,如果检查到用户输入不合法,可以通过setError()显示输入错误提示,以及setErrorEnabled(fasle)清除错误提示。
验证邮箱是否正确 
private static final String EMAIL_PATTERN = "^[a-zA-Z0-9#_~!$&‘()*+,;=:.\"(),:;<>@\\[\\]\\\\]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*$";
private Pattern pattern = Pattern.compile(EMAIL_PATTERN);
private Matcher matcher;

public boolean validateEmail(String email) {
    matcher = pattern.matcher(email);
    return matcher.matches();
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值