FAB、TextInputLayout及Snackbar笔记

本文详细介绍了FloatingActionButton(FAB)与TextInputLayout在Android应用中的使用方法,包括如何调整FAB的大小、背景颜色及阴影效果,以及TextInputLayout与EditText的结合使用,并实现了输入验证功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.youkuaiyun.com/feiduclear_up/article/details/46500865

http://blog.youkuaiyun.com/u010687392/article/details/46876679

转载于:https://www.cnblogs.com/i-love-kobe/p/5540393.html

浮动按钮(Floating Action Button)与视图切换的动画效果。项目地址:https://github.com/truizlop/FABRevealLayout 效果图:使用说明:FABRevealLayout用起来很简单。你只需在布局里面包含一个Design Support Library的FloatingActionButton以及两个view(这里称为主view与次view)。FABRevealLayout会自动摆放它们的位置并提供两个view之间的动画切换功能。<com.truizlop.fabreveallayout.FABRevealLayout     android:id="@ id/fab_reveal_layout"     android:layout_width="match_parent"     android:layout_height="@dimen/fab_reveal_height"     >       <android.support.design.widget.FloatingActionButton         android:layout_width="wrap_content"         android:layout_height="wrap_content"         app:backgroundTint="@color/some_color"         android:src="@drawable/some_drawable"         />       <RelativeLayout         android:id="@ id/main_view"         android:layout_width="match_parent"         android:layout_height="match_parent">           ...     </RelativeLayout>       <RelativeLayout         android:id="@ id/secondary_view"         android:layout_width="match_parent"         android:layout_height="match_parent">           ...     </RelativeLayout>   </com.truizlop.fabreveallayout.FABRevealLayout>请注意次view背景必须是透明的,那样color animation才能正常工作。更多动画在过渡效果发生期间,如果你想让FABRevealLayout里面的元素也显示动画,或者需要其他的任何操作,你可以注册一个listener。private void configureFABReveal(FABRevealLayout fabRevealLayout) {     fabRevealLayout.setOnRevealChangeListener(new OnRevealChangeListener() {         @Override         public void onMainViewAppeared(FABRevealLayout fabRevealLayout, View mainView) {}           @Override         public void onSecondaryViewAppeared(final FABRevealLayout fabRevealLayout, View secondaryView) {}     }); }或者,要主动出发reveal于隐藏动画的话,你可以用如下方法:fabRevealLayout.revealMainView(); fabRevealLayout.revealSecondaryView();局限目前,要让动画正常工作,FABRevealLayout内部的主view和次view高度必须相同。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值