重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要讲解了Android如何使用DecorView实现对话框功能,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。
创新互联公司专注于企业营销型网站、网站重做改版、泽库网站定制设计、自适应品牌网站建设、H5技术、商城网站建设、集团公司官网建设、成都外贸网站建设公司、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为泽库等各大城市提供网站开发制作服务。如果还不知道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; } }