国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Android - Android仿IOS UIAlertView對話框

Android仿IOS UIAlertView對話框

2022-03-06 20:26祝福 Android

這篇文章主要為大家詳細(xì)介紹了Android仿IOS UIAlertView對話框,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android仿IOS UIAlertView對話框的具體代碼,供大家參考,具體內(nèi)容如下

顯示效果:

Android仿IOS UIAlertView對話框

我在參考鏈接中看到了作者的仿的qq提示框,但是在使用的時候并不是很方面,有一些不足,于是我參照Android系統(tǒng)AlertDialog,使用參考鏈接中的布局文件和style文件,用自己的方法自定義了一下這個仿IOS上面UIAlertView的效果,這樣的話讓我們可以想使用系統(tǒng)AlertDialog一樣使用我自定義的CustomDialog。

CustomDialog使用代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.example.iosalertview;
 
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
 
import com.example.iosalertview.CustomDialog.Builder;
 
public class MainActivity extends Activity implements OnClickListener{
 private Button ios_dialog_btn,android_dialog_btn;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
   
  ios_dialog_btn = (Button) findViewById(R.id.ios_dialog_btn);
  android_dialog_btn = (Button) findViewById(R.id.android_dialog_btn);
   
  ios_dialog_btn.setOnClickListener(this);
  android_dialog_btn.setOnClickListener(this);
   
 }
 
 @Override
 public void onClick(View v) {
  switch (v.getId()) {
  case R.id.ios_dialog_btn:
   CustomDialog.Builder builder = new Builder(MainActivity.this);
   builder.setTitle(R.string.prompt);
   builder.setMessage(R.string.exit_app);
   builder.setPositiveButton(R.string.confirm, null);
   builder.setNegativeButton(R.string.cancel, null);
   builder.create().show();
   break;
  case R.id.android_dialog_btn:
   AlertDialog.Builder mbuilder = new AlertDialog.Builder(MainActivity.this);
   mbuilder.setTitle(R.string.prompt);
   mbuilder.setMessage(R.string.exit_app);
   mbuilder.setPositiveButton(R.string.confirm, null);
   mbuilder.setNegativeButton(R.string.cancel, null);
   mbuilder.create().show();
   break;
 
  default:
   break;
  }
 }
 
}

自定義CustomDialog代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package com.example.iosalertview;
 
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
 
public class CustomDialog extends Dialog {
 
 public CustomDialog(Context context) {
  super(context);
 }
 
 public CustomDialog(Context context, int theme) {
  super(context, theme);
 }
 
 public static class Builder {
  private Context context; //上下文對象
  private String title; //對話框標(biāo)題
  private String message; //對話框內(nèi)容
  private String confirm_btnText; //按鈕名稱“確定”
  private String cancel_btnText; //按鈕名稱“取消”
  private View contentView; //對話框中間加載的其他布局界面
  /*按鈕堅挺事件*/
  private DialogInterface.OnClickListener confirm_btnClickListener;
  private DialogInterface.OnClickListener cancel_btnClickListener;
 
  public Builder(Context context) {
   this.context = context;
  }
 
  /*設(shè)置對話框信息*/
  public Builder setMessage(String message) {
   this.message = message;
   return this;
  }
 
  /**
   * Set the Dialog message from resource
   *
   * @param title
   * @return
   */
  public Builder setMessage(int message) {
   this.message = (String) context.getText(message);
   return this;
  }
 
  /**
   * Set the Dialog title from resource
   *
   * @param title
   * @return
   */
  public Builder setTitle(int title) {
   this.title = (String) context.getText(title);
   return this;
  }
 
  /**
   * Set the Dialog title from String
   *
   * @param title
   * @return
   */
  public Builder setTitle(String title) {
   this.title = title;
   return this;
  }
 
  /**
   * 設(shè)置對話框界面
   * @param v View
   * @return
   */
  public Builder setContentView(View v) {
   this.contentView = v;
   return this;
  }
 
  /**
   * Set the positive button resource and it's listener
   *
   * @param confirm_btnText
   * @return
   */
  public Builder setPositiveButton(int confirm_btnText,
    DialogInterface.OnClickListener listener) {
   this.confirm_btnText = (String) context
     .getText(confirm_btnText);
   this.confirm_btnClickListener = listener;
   return this;
  }
 
  /**
   * Set the positive button and it's listener
   *
   * @param confirm_btnText
   * @return
   */
  public Builder setPositiveButton(String confirm_btnText,
    DialogInterface.OnClickListener listener) {
   this.confirm_btnText = confirm_btnText;
   this.confirm_btnClickListener = listener;
   return this;
  }
 
  /**
   * Set the negative button resource and it's listener
   *
   * @param confirm_btnText
   * @return
   */
  public Builder setNegativeButton(int cancel_btnText,
    DialogInterface.OnClickListener listener) {
   this.cancel_btnText = (String) context
     .getText(cancel_btnText);
   this.cancel_btnClickListener = listener;
   return this;
  }
 
  /**
   * Set the negative button and it's listener
   *
   * @param confirm_btnText
   * @return
   */
  public Builder setNegativeButton(String cancel_btnText,
    DialogInterface.OnClickListener listener) {
   this.cancel_btnText = cancel_btnText;
   this.cancel_btnClickListener = listener;
   return this;
  }
 
  public CustomDialog create() {
   LayoutInflater inflater = (LayoutInflater) context
     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   // instantiate the dialog with the custom Theme
   final CustomDialog dialog = new CustomDialog(context, R.style.mystyle);
   View layout = inflater.inflate(R.layout.customdialog, null);
   dialog.addContentView(layout, new LayoutParams(
     LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
   // set the dialog title
   ((TextView) layout.findViewById(R.id.title)).setText(title);
   ((TextView) layout.findViewById(R.id.title)).getPaint().setFakeBoldText(true);;
   // set the confirm button
   if (confirm_btnText != null) {
    ((Button) layout.findViewById(R.id.confirm_btn))
      .setText(confirm_btnText);
    if (confirm_btnClickListener != null) {
     ((Button) layout.findViewById(R.id.confirm_btn))
       .setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
         confirm_btnClickListener.onClick(dialog,
           DialogInterface.BUTTON_POSITIVE);
        }
       });
    }
   } else {
    // if no confirm button just set the visibility to GONE
    layout.findViewById(R.id.confirm_btn).setVisibility(
      View.GONE);
   }
   // set the cancel button
   if (cancel_btnText != null) {
    ((Button) layout.findViewById(R.id.cancel_btn))
      .setText(cancel_btnText);
    if (cancel_btnClickListener != null) {
     ((Button) layout.findViewById(R.id.cancel_btn))
       .setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
         cancel_btnClickListener.onClick(dialog,
           DialogInterface.BUTTON_NEGATIVE);
        }
       });
    }
   } else {
    // if no confirm button just set the visibility to GONE
    layout.findViewById(R.id.cancel_btn).setVisibility(
      View.GONE);
   }
   // set the content message
   if (message != null) {
    ((TextView) layout.findViewById(R.id.message)).setText(message);
   } else if (contentView != null) {
    // if no message set
    // add the contentView to the dialog body
    ((LinearLayout) layout.findViewById(R.id.message))
      .removeAllViews();
    ((LinearLayout) layout.findViewById(R.id.message)).addView(
      contentView, new LayoutParams(
        LayoutParams.WRAP_CONTENT,
        LayoutParams.WRAP_CONTENT));
   }
   dialog.setContentView(layout);
   return dialog;
  }
 
 }
}

demo下載地址:Android仿IOS UIAlertView對話框

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/zhufuing/article/details/18735371

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: www.国产 | 亚洲一区中文字幕在线观看 | 国产精品成人国产乱一区 | 国内精品视频在线观看 | 91电影在线| 中文一二区 | 欧美狠狠 | 榴莲视频成人在线观看 | 欧美日韩国产一区二区三区 | 色综久久 | 亚洲电影一区二区 | 亚洲午夜精品视频 | 婷婷在线视频 | 欧美性猛片aaaaaaa做受 | 欧美精三区欧美精三区 | 亚洲一区在线视频 | 久草在线 | 91免费影片 | 亚洲美女久久 | 91色乱码一区二区三区 | 日本三级不卡 | 久久久久久国产精品 | 日韩成年网站 | 久久久久亚洲精品 | 91久久精品日日躁夜夜躁国产 | 激情小网站 | 欧美一区二区三区不卡 | 亚洲精品1区| 一区二区精品在线视频 | 欧美视频免费在线 | 久久久久久国产精品 | 99久久国产露脸国语对白 | 欧美精品入口蜜桃 | 久久91| 成人免费视频008 | 亚洲精品电影 | 成人av电影在线观看 | 久久亚洲一区二区 | 国产精品成人一区二区三区 | 青青草国产在线 | 成人亚洲 |