时间:2021-05-19
如果还不知道DecorView,那也没有什么关系 ^_^
先来看看实现的效果
实现的大致思路
[下面大量 代码 ]
第一个对话框的实现
public class TipsDialog { private Activity activity; private View rootView; private TextView confirmTextView; private TextView cancelTextView; private TextView contentTextView; private boolean isShowing; public TipsDialog(Activity activity) { this.activity = activity; isShowing = false; rootView = LayoutInflater.from(activity).inflate(R.layout.view_tips_dialog,null); confirmTextView = (TextView) rootView.findViewById(R.id.view_tips_dialog_tv_confirm); cancelTextView = (TextView) rootView.findViewById(R.id.view_tips_dialog_tv_cancel); contentTextView = (TextView) rootView.findViewById(R.id.view_tips_dialog_tv_content); } public void show(){ if(activity == null){ return; } if(isShowing){ return; } ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); params.gravity = Gravity.CENTER; rootView.setLayoutParams(params); decorView.addView(rootView); rootView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); RotateAnimation rotateAnimation = new RotateAnimation(0,720f,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,0.5f); rotateAnimation.setDuration(2000); contentTextView.startAnimation(rotateAnimation); isShowing = true; } public void dismiss(){ if(!isShowing){ return; } isShowing = false; if(rootView.getParent() == null){ return; } ViewGroup parent = (ViewGroup) rootView.getParent(); parent.removeView(rootView); } public int getRandomColor(){ Random random = new Random(); return Color.argb(random.nextInt(200),random.nextInt(240),random.nextInt(240),random.nextInt(240)); } public boolean isShowing() { return isShowing; }}其实就是show的时候将布局添加到DecorView上面去,dismiss的时候将布局从DecorView上面移除
提示的实现(没有处理完善~~ 仅仅就是说明哈DecorView)
public class TopTipDialog { private Activity activity; private View rootView; private boolean isShowing; private static final int VIEW_HEIGHT = 64;//px public TopTipDialog(Activity activity) { this.activity = activity; rootView = LayoutInflater.from(activity).inflate(R.layout.view_top_tip_dialog,null); } public void show(){ if(isShowing){ return; } ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, VIEW_HEIGHT); params.gravity = Gravity.TOP; params.setMargins(0,0,0,-VIEW_HEIGHT); rootView.setLayoutParams(params); TranslateAnimation translateAnimation = new TranslateAnimation(0,0,-VIEW_HEIGHT,0); translateAnimation.setDuration(1500); translateAnimation.setFillAfter(true); decorView.addView(rootView); rootView.startAnimation(translateAnimation); rootView.postDelayed(new Runnable() { @Override public void run() { TranslateAnimation translateAnimation1 = new TranslateAnimation(0,0,0,-VIEW_HEIGHT); translateAnimation1.setDuration(1500); translateAnimation1.setFillAfter(true); rootView.startAnimation(translateAnimation1); } },3000); }}以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
在Android上没有标准的打开和另存为对话框。在本代码中,我将详细描述一个非常简单的打开和保存对话框实现过程,对于Android初学者来说非常有用,对话框都是
本文实例讲述了Android编程实现AlertDialog自定义弹出对话框的方法。分享给大家供大家参考,具体如下:弹出对话框,显示自定义的布局文件弹出对话框提示
android开发中实现单选与多选对话框的代码非常简单,具体代码如下所示:publicvoidmyClick(Viewview){//单选对话框//single
AndroidAlertDialog关系图如下:Android主要提供四种对话框:1:AlertDialog:功能最丰富,实际应用最广的对话框。2:Progre
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择。这些功能我们叫它AndroidDialog对话框,Ale