一步步走进Android MaterialDesign 之 其余小控件

剩下的东西不多了,都是一些普通的小组件

  • FloatingActionButton 这个就是那个圆形按钮。CoordinatorLayout支持锚点功能以及可以设置位于锚点的上下左右,所以FloatingActionButton可以设置在页面的任何一个地方,这一点有点类似于PopWindow。FloatingActionButton的背景颜色取决于你style里面的colorAccent值。同样AppBarLayout中运用了折叠属性的话,FloatingActionButton也会随之产生折叠隐藏显示的效果

这里写图片描述

  • Snackbar 这个跟Toast差不多,出现在页面的最底部。这没什么好说的,多一个action,可以加一些事件。比如删除列表某一行,可以用SnackBar产生一个提示,然后这个action作为撤销功能
float_action_button= (FloatingActionButton) findViewById(R.id.float_action_button);
        float_action_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar.make(v, "这是SnackBar", Snackbar.LENGTH_LONG).setAction("ok", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(NestedScrollViewActivity.this, "Toast", Toast.LENGTH_SHORT).show();
                    }
                }).show();
            }
        });
  • TextInputLayout 这个应该算是增强型EditText吧,也没什么好说的

这里写图片描述

textinputlayout=(TextInputLayout) findViewById(R.id.textinputlayout);
final EditText editText=textinputlayout.getEditText();
textinputlayout.setHint("UserName");
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.toString().length()>4) {
            textinputlayout.setErrorEnabled(true);
            textinputlayout.setError("length to large");
        }
        else {
            textinputlayout.setErrorEnabled(false);
        }
    }

    @Override
    public void afterTextChanged(Editable s) {

    }
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值