這篇文章主要講解了Android如何使用DecorView實現(xiàn)對話框功能,內(nèi)容清晰明了,對此有興趣的小伙伴可以學習一下,相信大家閱讀完之后會有幫助。

如果還不知道DecorView,那也沒有什么關系 ^_^
先來看看實現(xiàn)的效果


實現(xiàn)的大致思路
[下面大量 代碼 ]
第一個對話框的實現(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實現(xiàn)對話框功能-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://www.chinadenli.net/article28/dodscp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、App設計、網(wǎng)站策劃、企業(yè)建站、網(wǎng)站導航、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容