Material Design控件相关使用
2017-04-26 16:36
776 查看
第一种:
TextInputLayout和EditText配套使用,实现hint上浮效果
有两种写法:
1. 给TextInputLayout设置hint
代码:
2.给EditText设置hint
代码:
第二种:
TextInputLayout 输入框检查提示,会在输入框的下面显示错误提示信息
这里先提供一个参考的博客:
这里直接上代码:
这个是基于第一种效果的,也就是TextInputLayout和EditText必须是一对一的,而且TextInputLayout只能包一个EditText(而非其他控件),可以看到这里的TextInputLayout
用一个getEditText()获取它里面包含的EditText,提示相关的方法有:
1). TextInputLayout.setErrorEnable(boolean)
,true表示显示提示信息,false不显示。
2). [b]TextInputLayout.setError(string)设置提示信息,方法里面调用了setErrorEnable(true),所以不用在需要的地方专门设置这个属性。[/b]
效果图:
第三种:使用CardView实现卡片布局,边缘带阴影 ,使用如下:
gradle:
xml:
上面CardView中的属性也可以用代码,用法和注释如下:
cardView.setRadius(8);//设置图片圆角的半径大小
cardView.setCardElevation(8);//设置阴影部分大小
cardView.setContentPadding(5,5,5,5);//设置图片距离阴影大小
效果如下:
TextInputLayout和EditText配套使用,实现hint上浮效果
有两种写法:
1. 给TextInputLayout设置hint
代码:
<android.support.design.widget.TextInputLayout android:layout_margin="20dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="用户名"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" /> </android.support.design.widget.TextInputLayout>
2.给EditText设置hint
代码:
<android.support.design.widget.TextInputLayout android:layout_margin="20dp" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="密码"/> </android.support.design.widget.TextInputLayout>
第二种:
TextInputLayout 输入框检查提示,会在输入框的下面显示错误提示信息
这里先提供一个参考的博客:
这里直接上代码:
textInputLayout.getEditText().addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if(charSequence.length() < 6){ textInputLayout.setError("用户名不能少于6位!"); }else{ textInputLayout.setErrorEnabled(false); } } @Override public void afterTextChanged(Editable editable) { } });
这个是基于第一种效果的,也就是TextInputLayout和EditText必须是一对一的,而且TextInputLayout只能包一个EditText(而非其他控件),可以看到这里的TextInputLayout
用一个getEditText()获取它里面包含的EditText,提示相关的方法有:
1). TextInputLayout.setErrorEnable(boolean)
,true表示显示提示信息,false不显示。
2). [b]TextInputLayout.setError(string)设置提示信息,方法里面调用了setErrorEnable(true),所以不用在需要的地方专门设置这个属性。[/b]
效果图:
第三种:使用CardView实现卡片布局,边缘带阴影 ,使用如下:
gradle:
compile 'com.android.support:cardview-v7:25.1.1'
xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" app:cardCornerRadius="10dp" app:cardElevation="10dp" android:layout_margin="15dp"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:background="@color/white" android:layout_height="wrap_content"> <com.facebook.drawee.view.SimpleDraweeView android:layout_width="80dp" android:layout_height="80dp" android:layout_margin="10dp" android:background="@mipmap/bg"/> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_marginLeft="15dp" android:layout_marginTop="15dp" android:layout_marginBottom="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="14sp" android:text="如风而过"/> <TextView android:layout_marginLeft="15dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxLines="2" android:ellipsize="end" android:textSize="16sp" android:layout_marginRight="10dp" android:text="如风而过如风而过如风而过如风而过如风而过如风而过如风而过如风而过如风而过"/> </LinearLayout> </LinearLayout> </android.support.v7.widget.CardView> </LinearLayout>
上面CardView中的属性也可以用代码,用法和注释如下:
cardView.setRadius(8);//设置图片圆角的半径大小
cardView.setCardElevation(8);//设置阴影部分大小
cardView.setContentPadding(5,5,5,5);//设置图片距离阴影大小
效果如下:
相关文章推荐
- VC中在对话框上使用Rich Edit控件相关问题
- 使用WebBrowser控件播放Flash网页相关问题解决方法
- 基础控件相关使用
- 在5.0以下的设备上使用Material Design风格控件
- iOS开发中一些手写控件及其相关属性的使用
- WebBrowser控件使用相关
- Android Design Support Library 中控件的使用简单介绍(一)介绍 在这个 Lib 中主要包含了 8 个新的 material design 组件!最低支持 Android
- Material Design控件使用(四)
- 聚点相关的(在线Office)控件使用方法
- DataGridView 控件使用相关
- VC控件DateTimePicker使用方法及其相关
- VC控件DateTimePicker使用方法及其相关
- Material Design控件使用(二)
- VC关于使用了相关控件的程序出现:该内存不能为read的解决办法
- 分类网站中这种模式如下 如果不使用Datalist 将如何编制 使用怎样的控件操作 希望哪位大虾 提供相关代码
- DataGridView控件相关使用总结
- ASP.NET相关控件GridView和DetailsView的使用
- Material Design控件使用(完结篇)
- vb.net使用WebBrowser浏览器控件自制浏览器的相关技术
- 【148】DevExpress相关控件使用