├── .gitignore ├── LICENSE ├── README.md ├── codes ├── .gitignore ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── myapplication3 │ │ │ ├── AlertView.java │ │ │ └── MainActivity.java │ │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── alert_btn.xml │ │ ├── alert_btn_left.xml │ │ ├── alert_btn_left_sel.xml │ │ ├── alert_btn_right.xml │ │ ├── alert_btn_right_sel.xml │ │ ├── alert_btn_sel.xml │ │ ├── alert_dialog_left_selector.xml │ │ ├── alert_dialog_right_selector.xml │ │ ├── alert_dialog_selector.xml │ │ ├── dialog_bg.xml │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── item_listview.xml │ │ ├── view_alert_dialog.xml │ │ └── view_alert_dialog_muiltgroup.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── docs └── AlertView.md └── pic ├── AUI的logo.png └── AlertView示例.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | 43 | # Keystore files 44 | *.jks 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![logo](https://github.com/AweiLoveAndroid/AUI/blob/master/pic/AUI%E7%9A%84logo.png?raw=true) 2 | 3 | # AUI 4 | 5 | AUI是一个快速开发UI组件集合,帮助大家快速实现常用UI效果,用原生控件实现ios同样的UI效果,告别rn,weex等之类框架,提升开发效率。旨在帮助那些不想用或者不会用混合开发的,但是项目中又不得不实现仿ios的效果。集成这个库可以帮你快速实现常见的UI控件,分分钟搞定IOS效果。 6 | 7 | ---- 8 | 9 | # 主要功能列表(规划中): 10 | 11 | > 主要控件: 12 | 13 | * Button 按钮,可以设置圆角和自定义颜色图片。 14 | * Switch 开关按钮 15 | * Slider 滑块 16 | * Segment 分段控件 17 | * UIToolBar 工具栏 18 | * Picker 拾取器(选择器) :日期时间拾取器、普通单列拾取器、普通双列拾取器(非关联)、普通双列拾取器(关联) 19 | * ios里面的状态栏(Status bar) 相当于安卓的状态栏,只不过这个是可以设置颜色的 20 | * ios里面的导航栏(Navigationbar) 相当于安卓的标题栏 21 | * ios里面的标签栏(Tab bar) (系统定制) 相当于安卓app里面的tab导航标签页面 22 | * ios里面的工具栏(Tool bar) 这个适用于浏览器下方的那个导航 23 | * ios里面的搜索栏(Search bar) 这个在安卓里面需要自定义 24 | * ios里面的活动视图(Activity view) 相当于安卓的popwindow 25 | * ios里面的提醒视图([Alert view](docs/AlertView.md)) 相当于安卓的Diaolg,这个是居中的 26 | * ios里面的编辑菜单(Edit menu)相当于安卓的popwindow 27 | * ios里面的弹出视图(Popovers)相当于安卓的popwindow 28 | * ios里面的按钮,按钮开关,这个需要自定义一个View,支持圆角的ImageView 29 | * ios里面的分段控制(Segmented control) 这个在安卓里面需要自定义 30 | * ios里面的表视图(Table view) 其实就是列表展示,主要集成有几种常见的样式。 31 | 32 | > 其他效果: 33 | 34 | * 侧滑退出 35 | * 蒙版效果 36 | * 高斯模糊 37 | * 视差动画(比如类似QQ空间那种下拉图片放大) 38 | * 阻尼效果 39 | * 视差模糊 40 | * 转场动画(这个在ios里面带有一些,安卓里面基本都需要自定义) 41 | * 标题置顶(滑动列表时,让列表标题置顶,用于多类型布局场景,比如联系人界面) 42 | 43 | ---- 44 | 45 | # 使用方法: 46 | 47 | ---- 48 | 49 | # 更新日志: 50 | 51 | * 2019.3.22 更新AlertView 52 | 53 | ---- 54 | # 版权: 55 | 56 | 57 | Copyright [awei] [AWeiLoveAndroid] 58 | 59 | Licensed under the Apache License, Version 2.0 (the "License"); 60 | you may not use this file except in compliance with the License. 61 | You may obtain a copy of the License at 62 | 63 | http://www.apache.org/licenses/LICENSE-2.0 64 | 65 | Unless required by applicable law or agreed to in writing, software 66 | distributed under the License is distributed on an "AS IS" BASIS, 67 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 68 | See the License for the specific language governing permissions and 69 | limitations under the License. 70 | -------------------------------------------------------------------------------- /codes/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /codes/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /codes/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.example.myapplication3" 7 | minSdkVersion 21 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:28.0.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 28 | } 29 | -------------------------------------------------------------------------------- /codes/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /codes/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /codes/app/src/main/java/com/example/myapplication3/AlertView.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication3; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Dialog; 5 | import android.content.Context; 6 | import android.support.v4.content.ContextCompat; 7 | import android.text.TextUtils; 8 | import android.view.Display; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.view.WindowManager; 13 | import android.widget.BaseAdapter; 14 | import android.widget.Button; 15 | import android.widget.FrameLayout; 16 | import android.widget.LinearLayout; 17 | import android.widget.ListView; 18 | import android.widget.TextView; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * 高仿IOS的AlertView 24 | */ 25 | @SuppressLint("AppCompatCustomView") 26 | public class AlertView{ 27 | 28 | private Context context; 29 | private Dialog dialog; 30 | 31 | // 普通两个按钮布局使用的控件 32 | private LinearLayout lLayout_bg; 33 | private TextView txt_title; 34 | private TextView txt_msg; 35 | private Button btn_neg; 36 | private Button btn_pos; 37 | private View img_line; 38 | private ListView listView; 39 | 40 | // 多个按钮布局使用的控件 41 | private LinearLayout lLayout_bg2; 42 | private TextView txt_title2; 43 | private TextView txt_msg2; 44 | private Button btn_neg2; 45 | private Button btn_pos2; 46 | 47 | private Display display; 48 | private boolean showTitle = false; 49 | private boolean showMsg = false; 50 | private boolean showPosBtn = false; 51 | private boolean showNegBtn = false; 52 | private boolean isMultiGroup = false; 53 | 54 | public AlertView(Context context) { 55 | this.context = context; 56 | WindowManager windowManager = (WindowManager) context 57 | .getSystemService(Context.WINDOW_SERVICE); 58 | display = windowManager.getDefaultDisplay(); 59 | } 60 | 61 | public AlertView builder() { 62 | builder(false); 63 | return this; 64 | } 65 | 66 | public AlertView builder(boolean isMultiGroup) { 67 | View view = null; 68 | View view2 = null; 69 | this.isMultiGroup = isMultiGroup; 70 | if(isMultiGroup == false){ 71 | view = LayoutInflater.from(context).inflate( 72 | R.layout.view_alert_dialog, null); 73 | lLayout_bg = (LinearLayout) view.findViewById(R.id.lLayout_bg); 74 | txt_title = (TextView) view.findViewById(R.id.txt_title); 75 | txt_msg = (TextView) view.findViewById(R.id.txt_msg); 76 | btn_neg = (Button) view.findViewById(R.id.btn_neg); 77 | btn_pos = (Button) view.findViewById(R.id.btn_pos); 78 | img_line = (View) view.findViewById(R.id.img_line); 79 | }else{ // 按钮超过2个 80 | view2 = LayoutInflater.from(context).inflate( 81 | R.layout.view_alert_dialog_muiltgroup, null); 82 | lLayout_bg2 = (LinearLayout) view2.findViewById(R.id.lLayout_bg2); 83 | txt_title2 = (TextView) view2.findViewById(R.id.txt_title2); 84 | txt_msg2 = (TextView) view2.findViewById(R.id.txt_msg2); 85 | listView = (ListView) view2.findViewById(R.id.lv_multi); 86 | btn_neg2 = (Button) view2.findViewById(R.id.btn_neg2); 87 | btn_pos2 = (Button) view2.findViewById(R.id.btn_pos2); 88 | } 89 | setGone(); 90 | dialog = new Dialog(context, R.style.AlertDialogStyle); 91 | if(isMultiGroup == false) { 92 | dialog.setContentView(view); 93 | lLayout_bg.setLayoutParams( 94 | new FrameLayout.LayoutParams((int) (display.getWidth() * 0.85), 95 | FrameLayout.LayoutParams.WRAP_CONTENT)); 96 | }else{ 97 | dialog.setContentView(view2); 98 | lLayout_bg2.setLayoutParams(new FrameLayout.LayoutParams( 99 | FrameLayout.LayoutParams.MATCH_PARENT, 100 | FrameLayout.LayoutParams.MATCH_PARENT)); 101 | } 102 | return this; 103 | } 104 | 105 | /** 106 | * 恢复初始 107 | * @return 108 | */ 109 | public AlertView setGone() { 110 | if (lLayout_bg != null) { 111 | txt_title.setVisibility(View.GONE); 112 | txt_msg.setVisibility(View.GONE); 113 | btn_neg.setVisibility(View.GONE); 114 | btn_pos.setVisibility(View.GONE); 115 | img_line.setVisibility(View.GONE); 116 | 117 | } 118 | if (lLayout_bg2 != null) { 119 | txt_title2.setVisibility(View.GONE); 120 | txt_msg2.setVisibility(View.GONE); 121 | btn_pos2.setVisibility(View.GONE); 122 | // listView.setVisibility(View.GONE); 123 | } 124 | showTitle = false; 125 | showMsg = false; 126 | showPosBtn = false; 127 | showNegBtn = false; 128 | return this; 129 | } 130 | 131 | /** 132 | * 设置title 133 | * @param title 134 | * @return 135 | */ 136 | public AlertView setTitle(String title) { 137 | showTitle = true; 138 | if (isMultiGroup==true){ 139 | if (TextUtils.isEmpty(title)) { 140 | txt_title2.setText("提示"); 141 | } else { 142 | txt_title2.setText(title); 143 | } 144 | } else{ 145 | if (TextUtils.isEmpty(title)) { 146 | txt_title.setText("提示"); 147 | } else { 148 | txt_title.setText(title); 149 | } 150 | } 151 | return this; 152 | } 153 | 154 | /** 155 | * 设置Message 156 | * @param msg 157 | * @return 158 | */ 159 | public AlertView setMsg(String msg) { 160 | showMsg = true; 161 | if (isMultiGroup==true){ 162 | if (TextUtils.isEmpty(msg)) { 163 | txt_msg2.setText("提示"); 164 | } else { 165 | txt_msg2.setText(msg); 166 | } 167 | } else{ 168 | if (TextUtils.isEmpty(msg)) { 169 | txt_msg.setText("提示"); 170 | } else { 171 | txt_msg.setText(msg); 172 | } 173 | } 174 | return this; 175 | } 176 | 177 | /** 178 | * 设置点击外部是否消失 179 | * @param cancel 180 | * @return 181 | */ 182 | public AlertView setCancelable(boolean cancel) { 183 | dialog.setCancelable(cancel); 184 | return this; 185 | } 186 | 187 | /** 188 | * 右侧按钮 189 | * 190 | * @param text 191 | * @param listener 192 | * @return 193 | */ 194 | public AlertView setPositiveButton(String text, 195 | final View.OnClickListener listener) { 196 | return setPositiveButton(text, -1, listener); 197 | } 198 | 199 | public AlertView setPositiveButton(String text, int color, 200 | final View.OnClickListener listener) { 201 | showPosBtn = true; 202 | if (color == -1) { 203 | color = R.color.action_sheet_blue; 204 | } 205 | if (isMultiGroup==true){ 206 | if ("".equals(text)) { 207 | btn_pos2.setText(""); 208 | } else { 209 | btn_pos2.setText(text); 210 | } 211 | btn_pos2.setTextColor(ContextCompat.getColor(context, color)); 212 | 213 | btn_pos2.setOnClickListener(new View.OnClickListener() { 214 | @Override 215 | public void onClick(View v) { 216 | if (listener != null) 217 | listener.onClick(v); 218 | dismiss(); 219 | } 220 | }); 221 | }else{ 222 | if ("".equals(text)) { 223 | btn_pos.setText(""); 224 | } else { 225 | btn_pos.setText(text); 226 | } 227 | btn_pos.setTextColor(ContextCompat.getColor(context, color)); 228 | btn_pos.setOnClickListener(new View.OnClickListener() { 229 | @Override 230 | public void onClick(View v) { 231 | if (listener != null) 232 | listener.onClick(v); 233 | dismiss(); 234 | } 235 | }); 236 | } 237 | return this; 238 | } 239 | 240 | /** 241 | * 左侧按钮 242 | * 243 | * @param text 244 | * @param listener 245 | * @return 246 | */ 247 | 248 | public AlertView setNegativeButton(String text, 249 | final View.OnClickListener listener) { 250 | 251 | return setNegativeButton(text, -1, listener); 252 | } 253 | 254 | public AlertView setNegativeButton(String text, int color, 255 | final View.OnClickListener listener) { 256 | showNegBtn = true; 257 | if ("".equals(text)) { 258 | btn_neg.setText(""); 259 | } else { 260 | btn_neg.setText(text); 261 | } 262 | if (color == -1) { 263 | color = R.color.action_sheet_blue; 264 | } 265 | btn_neg.setTextColor(ContextCompat.getColor(context, color)); 266 | 267 | btn_neg.setOnClickListener(new View.OnClickListener() { 268 | @Override 269 | public void onClick(View v) { 270 | if (listener != null) 271 | listener.onClick(v); 272 | dismiss(); 273 | } 274 | }); 275 | return this; 276 | } 277 | 278 | /** 279 | * 设置显示 280 | */ 281 | private void setLayout() { 282 | if(isMultiGroup==false){ // 两个按钮 283 | if (!showTitle && !showMsg) { 284 | txt_title.setText(""); 285 | txt_title.setVisibility(View.VISIBLE); 286 | } 287 | 288 | if (showTitle) { 289 | txt_title.setVisibility(View.VISIBLE); 290 | } 291 | 292 | if (showMsg) { 293 | txt_msg.setVisibility(View.VISIBLE); 294 | } 295 | 296 | if (!showPosBtn && !showNegBtn) { 297 | btn_pos.setText(""); 298 | btn_pos.setVisibility(View.VISIBLE); 299 | btn_pos.setBackgroundResource(R.drawable.alert_dialog_selector); 300 | btn_pos.setOnClickListener(new View.OnClickListener() { 301 | @Override 302 | public void onClick(View v) { 303 | dismiss(); 304 | } 305 | }); 306 | } 307 | 308 | if (showPosBtn && showNegBtn) { 309 | btn_pos.setVisibility(View.VISIBLE); 310 | btn_pos.setBackgroundResource(R.drawable.alert_dialog_right_selector); 311 | btn_neg.setVisibility(View.VISIBLE); 312 | btn_neg.setBackgroundResource(R.drawable.alert_dialog_left_selector); 313 | img_line.setVisibility(View.VISIBLE); 314 | } 315 | 316 | if (showPosBtn && !showNegBtn) { 317 | btn_pos.setVisibility(View.VISIBLE); 318 | btn_pos.setBackgroundResource(R.drawable.alert_dialog_selector); 319 | } 320 | 321 | if (!showPosBtn && showNegBtn) { 322 | btn_neg.setVisibility(View.VISIBLE); 323 | btn_neg.setBackgroundResource(R.drawable.alert_dialog_selector); 324 | } 325 | }else{ // 多个按钮 326 | if (!showTitle && !showMsg) { 327 | txt_title2.setText(""); 328 | txt_title2.setVisibility(View.VISIBLE); 329 | } 330 | if (showTitle) { 331 | txt_title2.setVisibility(View.VISIBLE); 332 | } 333 | if (showMsg) { 334 | txt_msg2.setVisibility(View.VISIBLE); 335 | } 336 | 337 | if (showPosBtn) { 338 | btn_pos2.setVisibility(View.VISIBLE); 339 | btn_pos2.setBackgroundResource(R.drawable.alert_dialog_selector); 340 | btn_pos2.setOnClickListener(new View.OnClickListener() { 341 | @Override 342 | public void onClick(View v) { 343 | dismiss(); 344 | } 345 | }); 346 | } 347 | } 348 | 349 | } 350 | 351 | public void show() { 352 | setLayout(); 353 | dialog.show(); 354 | } 355 | 356 | public boolean isShowing() { 357 | if (dialog != null) { 358 | if (dialog.isShowing()) 359 | return true; 360 | else 361 | return false; 362 | } 363 | return false; 364 | } 365 | 366 | public void dismiss() { 367 | if (dialog!=null){ 368 | dialog.dismiss(); 369 | } 370 | 371 | } 372 | 373 | /** 374 | * 设置多组按钮 375 | */ 376 | public AlertView setMultiGroupBtn(final List data){ 377 | listView.setDividerHeight(1); 378 | listView.setAdapter(new MyAdapter(context,data)); 379 | return this; 380 | } 381 | 382 | // 四种自带风格 383 | enum AlertViewStyle{ 384 | MORMAL, // 默认风格,无输入框 UIAlertViewStyleDefault 385 | PASSWORD_INPUT, // 密码输入风格 UIAlertViewStyleSecureTextInput 386 | NORMAL_INPUT, // 普通输入框 UIAlertViewStylePlainTextInput 387 | Login_PASSWORD_INPUT // 账号密码框风格 UIAlertViewStyleLoginAndPasswordInput 388 | } 389 | 390 | class MyAdapter extends BaseAdapter{ 391 | 392 | private List mData; 393 | private LayoutInflater mInflater; 394 | 395 | public MyAdapter(Context context, List data) { 396 | mData = data; 397 | mInflater = LayoutInflater.from(context); 398 | } 399 | 400 | @Override 401 | public int getCount() { 402 | return mData.size(); 403 | } 404 | 405 | @Override 406 | public Object getItem(int position) { 407 | return mData.get(position); 408 | } 409 | 410 | @Override 411 | public long getItemId(int position) { 412 | return position; 413 | } 414 | 415 | @Override 416 | public View getView(int position, View convertView, ViewGroup parent) { 417 | View view = mInflater.inflate(R.layout.item_listview,parent,false); 418 | Button btnBeg2 = (Button) view.findViewById(R.id.btn_neg2); 419 | btnBeg2.setText(mData.get(position).toString()); 420 | btnBeg2.setBackgroundResource(R.drawable.alert_dialog_left_selector); 421 | return view; 422 | } 423 | } 424 | } -------------------------------------------------------------------------------- /codes/app/src/main/java/com/example/myapplication3/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.myapplication3; 2 | 3 | import android.content.DialogInterface; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AlertDialog; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | import android.widget.Toast; 9 | 10 | import java.util.ArrayList; 11 | 12 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 13 | 14 | AlertView alertView; 15 | AlertView alertView2; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | findViewById(R.id.btn).setOnClickListener(this); 22 | findViewById(R.id.btn2).setOnClickListener(this); 23 | findViewById(R.id.btn3).setOnClickListener(this); 24 | findViewById(R.id.btn4).setOnClickListener(this); 25 | findViewById(R.id.btn5).setOnClickListener(this); 26 | findViewById(R.id.btn6).setOnClickListener(this); 27 | alertView = new AlertView(MainActivity.this).builder(); 28 | alertView2 = new AlertView(MainActivity.this).builder(true); 29 | } 30 | 31 | @Override 32 | public void onClick(View v) { 33 | switch (v.getId()) { 34 | case R.id.btn: 35 | AlertDialog.Builder localBuilder = new AlertDialog.Builder(MainActivity.this); 36 | localBuilder.setTitle("简单对话框"); 37 | localBuilder.setIcon(R.mipmap.ic_launcher); 38 | localBuilder.setMessage("提示信息?"); 39 | localBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener() { 40 | public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) { 41 | Toast.makeText(MainActivity.this, "确定", Toast.LENGTH_SHORT).show(); 42 | } 43 | }); 44 | localBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() { 45 | public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) { 46 | Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show(); 47 | } 48 | }); 49 | 50 | /*** 51 | * 设置点击返回键不会消失 52 | * */ 53 | localBuilder.setCancelable(false).create(); 54 | 55 | localBuilder.show(); 56 | break; 57 | case R.id.btn2: 58 | alertView.setGone() 59 | .setTitle("提示") 60 | .setMsg("基本使用") 61 | .setNegativeButton("取消", null) 62 | .setPositiveButton("确定", new View.OnClickListener() { 63 | @Override 64 | public void onClick(View v) { 65 | Toast.makeText(MainActivity.this, 66 | "点击了确定", Toast.LENGTH_SHORT).show(); 67 | } 68 | }) 69 | .show(); 70 | break; 71 | case R.id.btn3: 72 | alertView.setGone() 73 | .setMsg("修改按钮颜色") 74 | .setNegativeButton("取消", R.color.colorAccent,null) 75 | .setPositiveButton("确定", R.color.colorAccent,null) 76 | .show(); 77 | break; 78 | case R.id.btn4: 79 | alertView.setGone() 80 | .setMsg("弹出确定按钮") 81 | .setPositiveButton("确定",null) 82 | .show(); 83 | break; 84 | case R.id.btn5: 85 | alertView.setGone() 86 | .setMsg("弹出取消按钮") 87 | .setNegativeButton("取消",null) 88 | .setCancelable(true) 89 | .show(); 90 | break; 91 | case R.id.btn6: 92 | ArrayList arrayList = new ArrayList(); 93 | arrayList.add("按钮1"); 94 | arrayList.add("按钮2"); 95 | arrayList.add("按钮3"); 96 | arrayList.add("按钮4"); 97 | arrayList.add("按钮5"); 98 | arrayList.add("按钮6"); 99 | alertView2.setGone() 100 | .setTitle("弹出多个按钮") 101 | .setMsg("这是弹出取消按钮的示例") 102 | .setMultiGroupBtn(arrayList) 103 | .setPositiveButton("取消",null) 104 | .setCancelable(true) 105 | .show(); 106 | break; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable/alert_btn.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 8 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable/alert_btn_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable/alert_btn_left_sel.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable/alert_btn_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable/alert_btn_right_sel.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable/alert_btn_sel.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable/alert_dialog_left_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable/alert_dialog_right_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable/alert_dialog_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable/dialog_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /codes/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /codes/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |