android app自动更新界面_Android自定义view之模仿登录界面文本输入框(华为云APP)...
好久不见!!!!!,最近终于挤出时间来更新文章了,废话不多说,直接开始。
效果图如下:
01
分析
1.组合多个控件完成此输入框静态效果
2.hint值上浮下潜动画
3.一些功能
02
步骤
01
自定义一个控件
public class MyEditVIew extends RelativeLayout { public MyEditVIew(Context context) { super(context,null); } public MyEditVIew(Context context, AttributeSet attrs) { super(context, attrs,0); } public MyEditVIew(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }}
02
写一个相似布局(代码在最后)
03
将布局打气到View中
LayoutInflater.from(context).inflate(R.layout.my_edit_view, this);
04
小提示文字上浮下潜动画
//小提示文字出现动画 private void minTextshow(TextView textView) { AnimationSet animationSet = new AnimationSet(true); Animation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f); Animation alphaAnimation = new AlphaAnimation(0, 1f); animationSet.addAnimation(mHiddenAction); animationSet.addAnimation(alphaAnimation); animationSet.setDuration(300); textview.startAnimation(animationSet); } //小提示文字隐藏动画 private void minTexthide(TextView textView) { AnimationSet animationSet = new AnimationSet(true); Animation mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f); mShowAction.setRepeatMode(Animation.REVERSE); Animation alphaAnimation = new AlphaAnimation(1f, 0); animationSet.addAnimation(mShowAction); animationSet.addAnimation(alphaAnimation); animationSet.setRepeatMode(Animation.REVERSE); animationSet.setDuration(300); textview.startAnimation(animationSet); CountDownTimer countDownTimer = new CountDownTimer(300, 300) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { textview.setText(""); } }.start(); }
05
密码加密解密显示
//设置文字非加密 HideReturnsTransformationMethod method = HideReturnsTransformationMethod.getInstance(); edittext.setTransformationMethod(method); //设置文字加密 TransformationMethod method = PasswordTransformationMethod.getInstance(); edittext.setTransformationMethod(method);
06
其他一些小知识点
1.将光标移到最后
//将光标移到最后edittext.setSelection(edittext.getText().toString().length());
2.将键盘中的回车和空格去除
public static void setEditTextInputSpace(EditText editText) { InputFilter filter = new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { if (source.equals(" ") || source.toString().contentEquals("\n")) { return ""; } else { return null; } } }; editText.setFilters(new InputFilter[]{filter}); }
3.给自定义view对外提供一个获取值的方法
public String getText() { return edittext.getText().toString(); }
07
源码
1.MyEditVIew.java
public class MyEditVIew extends RelativeLayout { private TextView textview; private EditText edittext; private boolean mtextisshow; //文字是否显示判断 private boolean imgisshow; //图片是否显示判断 private String hintText; private ImageView imageView; private ImageView iV_clean; public MyEditVIew(Context context) { super(context,null); } public MyEditVIew(Context context, AttributeSet attrs) { super(context, attrs,0); init(context, attrs); setEditTextInputSpace(edittext); textAddChanged(); imageOnClick(); } public MyEditVIew(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } //打气布局,获取自定义属性的值 private void init(Context context, AttributeSet attrs) { LayoutInflater.from(context).inflate(R.layout.my_edit_view, this); textview = findViewById(R.id.textview); edittext = findViewById(R.id.edittext); imageView = findViewById(R.id.imageView); iV_clean=findViewById(R.id.iV_clean); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MyEditVIew); hintText = ta.getString(R.styleable.MyEditVIew_myhintText); } //文字输入监听以及一些逻辑处理(未优化) private void textAddChanged(){ 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) { } @Override public void afterTextChanged(Editable s) { int textSum = s.toString().trim().length(); if (textSum == 0) { if (mtextisshow == true) { minTexthide(textview); mtextisshow = false; iV_clean.setVisibility(INVISIBLE); edittext.setHint(hintText); } } else { if (imgisshow) { //设置文字非加密 HideReturnsTransformationMethod method = HideReturnsTransformationMethod.getInstance(); edittext.setTransformationMethod(method); edittext.setSelection(edittext.getText().toString().length()); } else { //设置文字加密 TransformationMethod method = PasswordTransformationMethod.getInstance(); edittext.setTransformationMethod(method); //将光标移到最后 edittext.setSelection(edittext.getText().toString().length()); } if (mtextisshow == false) { textview.setText(hintText); minTextshow(textview); iV_clean.setVisibility(VISIBLE); mtextisshow = true; } } } }); } //两个图片的点击事件,加密,清除文字 private void imageOnClick(){ imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (imgisshow) { imageView.setImageResource(R.mipmap.password_show); HideReturnsTransformationMethod method = HideReturnsTransformationMethod.getInstance(); edittext.setTransformationMethod(method); edittext.setSelection(edittext.getText().toString().length()); imgisshow = false; } else { imageView.setImageResource(R.mipmap.pwd_invisible); TransformationMethod method = PasswordTransformationMethod.getInstance(); edittext.setTransformationMethod(method); edittext.setSelection(edittext.getText().toString().length()); imgisshow = true; } } }); iV_clean.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { edittext.setText(""); } }); } //小提示文字出现动画 private void minTextshow(TextView textView) { AnimationSet animationSet = new AnimationSet(true); Animation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f); Animation alphaAnimation = new AlphaAnimation(0, 1f); animationSet.addAnimation(mHiddenAction); animationSet.addAnimation(alphaAnimation); animationSet.setDuration(300); textview.startAnimation(animationSet); } //小提示文字隐藏动画 private void minTexthide(TextView textView) { AnimationSet animationSet = new AnimationSet(true); Animation mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f); mShowAction.setRepeatMode(Animation.REVERSE); Animation alphaAnimation = new AlphaAnimation(1f, 0); animationSet.addAnimation(mShowAction); animationSet.addAnimation(alphaAnimation); animationSet.setRepeatMode(Animation.REVERSE); animationSet.setDuration(300); textview.startAnimation(animationSet); CountDownTimer countDownTimer = new CountDownTimer(300, 300) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { textview.setText(""); } }.start(); } //将键盘中的回车和空格去除 public static void setEditTextInputSpace(EditText editText) { InputFilter filter = new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { if (source.equals(" ") || source.toString().contentEquals("\n")) { return ""; } else { return null; } } }; editText.setFilters(new InputFilter[]{filter}); } //提供一个可获取的值 public String getText() { return edittext.getText().toString(); }}
2.my_edit_view.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingLeft="4dp" android:paddingRight="4dp" > <TextView android:id="@+id/textview" android:textSize="12sp" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#b1b1b1" android:layout_marginRight="16dp" android:layout_marginLeft="16dp"/><LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/edittext" android:layout_weight="1" android:layout_height="wrap_content" android:background="@null" android:hint="密码" android:textSize="22sp" android:layout_width="0dp" android:layout_marginLeft="16dp" android:layout_marginBottom="6dp" android:lines="1" /> <ImageView android:id="@+id/iV_clean" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/clean" android:visibility="invisible" android:layout_marginRight="4dp"/> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/pwd_invisible" android:layout_marginRight="16dp"/> LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="1dp" android:background="#b1b1b1" android:layout_marginRight="16dp" android:layout_marginLeft="16dp"/>LinearLayout>
3.attrs文件
<declare-styleable name="MyEditVIew"> <attr name="myhintText" format="string"/> declare-styleable>
希望对你有所帮助,我们下一篇文章见!
微信公众号|计蒙不吃鱼
OSCHINA | 计蒙不吃鱼
新浪微博|计蒙不吃鱼
CSDN | 计蒙不吃鱼
android app自动更新界面_Android自定义view之模仿登录界面文本输入框(华为云APP)...相关推荐
- Android自定义view之模仿登录界面文本输入框(华为云APP)
6.其他一些小知识点 1.将光标移到最后 //将光标移到最后 edittext.setSelection(edittext.getText().toString().length()); 2.将键盘中 ...
- android 清空canvas部分内容_Android自定义View实现圆形头像效果
在我们的APP中通常会遇到,展示圆形头像的需求,一般通过Glide就能实现,但是让我们做一个圆形头像,如果让我们自定义实现这种效果,该怎样做呢? 好,接下来本文通过三种方式来实现这种效果! 注意:这是 ...
- android记账本折线图_Android自定义View - 仿支付宝月账单折线图
前言 支付宝有个查看月账单的功能,最近一直在学习自定义View,于是就尝试着自己实现了一个类似的折线图. 下面是支付宝消费分析功能截图和自己实现的折线效果截图: 支付宝消费分析折线图.jpg 效果1. ...
- android 手写签批_Android自定义View——手写签批
接到一个领导批示保留原笔迹的功能,类似于绘画板,用户打开后可以绘制,点击完成后以图片的形式保存在本地,并且显示绘制后图片,上传服务器,达到保留原笔迹的目的.可以运用于签字.审批等. 效果图: 手写签批 ...
- 安卓APP自动更新功能实现
安卓APP自动更新功能实现 前言 代码实现 前言 安卓App自动更新基本上是每个App都需要具备的功能,接下来介绍一下实现自动更新的步骤. 代码实现 App自动更新主要分为新版本检测.升级弹窗.下载升 ...
- android通知栏应用程序更新,Android App自动更新之通知栏下载
本文实例为大家分享了Android App自动更新通知栏下载的具体代码,供大家参考,具体内容如下 版本更新说明 这里有调用UpdateService启动服务检查下载安装包等 1. 文件下载,下完后写入 ...
- Android APP 自动更新实现(适用Android9.0)
Android App自动更新基本上是每个App都需具备的功能,参考网上各种资料,自己整理了下,先来看看大致的界面: 一.实现思路: 1.发布Android App时,都会生成output-metad ...
- Android如何实现APP自动更新
先来看看要实现的效果图: 对于安卓用户来说,手机应用市场说满天飞可是一点都不夸张,比如小米,魅族,百度,360,机锋,应用宝等等,当我们想上线一款新版本APP时,先不说渠道打包的麻烦,单纯指上传APP ...
- Android App自动更新解决方案(DownloadManager)
Android App自动更新解决方案(DownloadManager) 参考文章: (1)Android App自动更新解决方案(DownloadManager) (2)https://www.cn ...
最新文章
- Annotataion
- unity调用普通java类_Unity中C#和Java的相互调用实例代码
- 用WinEdt打开.tex文件显示error reading错误
- winCVS 使用方法
- Linux文件和目录属性
- JavaScript快速入门(四)——JavaScript函数
- Python中的魔法方法
- 有关链表的小技巧,我都给你总结好了
- 链队列基本运算的实现
- 新手用手机学黑客编程一秒变黑客
- 夏普利值:全排列边际效益的平均
- Android KeyStore的使用
- 《失业的程序员》(十二):潜意识的智商 .
- 基于ssm的学生管理系统源码+开题报告、任务书、文献综述
- Java开发WIN10动态壁纸
- 状告技术总监,索赔 90 万元,称其拖延研发进度、系统频繁崩溃出错、产品质量存在严重问题...
- 什么是代理(Proxy)?
- 娄底环宇中等职业技术学校
- 看完这篇文章,保你学会C语言 :for 循环
- 公众号运营该如何快速找到内容方向定位?
热门文章
- centos6.6 安装python环境及Django 1.9.0
- maven创建的工程eclipse 项目--属性--为什么没有deployment assembly 按钮呢
- maven环境下使用java、scala混合开发spark应用
- MySQL事务隔离级别和Spring事务关系介绍
- 性能监控/优化系列——JVM监控/调优
- JVM调优系列:(三)类加载和执行机制
- 腾讯从百度挖来的AI Lab负责人张潼离职,要去阿里?...
- Pandas库学习笔记
- BIOS设置开机密码
- 记录从前端到后端--博客项目