這篇文章主要講解了Android如何使用DecorView實(shí)現(xiàn)對(duì)話框功能,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。
創(chuàng)新互聯(lián)公司專注于企業(yè)營(yíng)銷型網(wǎng)站、網(wǎng)站重做改版、澤庫(kù)網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5技術(shù)、商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為澤庫(kù)等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。如果還不知道DecorView,那也沒(méi)有什么關(guān)系 ^_^
先來(lái)看看實(shí)現(xiàn)的效果
實(shí)現(xiàn)的大致思路
[下面大量 代碼 ]
第一個(gè)對(duì)話框的實(shí)現(xiàn)
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; } }
網(wǎng)站名稱:Android如何使用DecorView實(shí)現(xiàn)對(duì)話框功能-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://muchs.cn/article28/dodscp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、App設(shè)計(jì)、網(wǎng)站策劃、企業(yè)建站、網(wǎng)站導(dǎo)航、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容