FAB、TextInputLayout及Snackbar笔记

FloatingActionButton

由于FloatingActionButton是重写ImageView的,所有FloatingActionButton拥有ImageView的一切属性.

控制FloatingActionButton的大小,背景颜色,阴影的深度等:

  1. app:fabSize 有两种赋值分别是 “mini” 和 “normal”,默认是“normal”.
  2. app:backgroundTint 默认的背景颜色是Theme主题中的
  3. app:elevation 阴影面积,dp为单位,越大阴影面积越大

注意:不能通过 android:background 属性来改变背景颜色,只能通过app:backgroundTint,因为FAB是继承自ImageView的。

TextInputLayout

里面需要放一个EidtText

<android.support.design.widget.TextInputLayout
        android:id="@+id/textInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </android.support.design.widget.TextInputLayout>
final TextInputLayout  inputLayout = findView(R.id.textInput);
        inputLayout.setHint("input:");
        EditText editText = inputLayout.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()>4){
                    inputLayout.setErrorEnabled(true);//设置是否显示错误信息
                    inputLayout.setError("error text");
                }else{
                    inputLayout.setErrorEnabled(false);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

这个不知道为什么,我这的错误信息只会显示一次,删掉,重新写就不会出现了,OTZ……<待解决……

Snackbar

final Snackbar snackbar = Snackbar.make(view,"text",Snackbar.LENGTH_LONG);
snackbar.setActionTextColor(getResources().getColor(R.color.colorPrimary));
snackbar.setAction("undo", new View.OnClickListener() {
@Override
public void onClick(View view) {
snackbar.dismiss();
}
}).show();

 

参考文章:

http://blog.csdn.net/feiduclear_up/article/details/46500865

http://blog.csdn.net/u010687392/article/details/46876679

原文地址:https://www.cnblogs.com/i-love-kobe/p/5540393.html