MD风格

来源:互联网 发布:软件测试外包 编辑:程序博客网 时间:2024/05/16 01:22

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();}






0 0