Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说
安卓蒙层实现_android 自定义消息弹窗,希望能够帮助你!!!。
android在执行程序过程中,很可能会用到,正在执行的提示.下面我们就自己做一个提示框,自带蒙板,执行过程中,后面的窗口内容不能操作.
下面的代码可以直接复制粘贴使用:
1.首先写一个WaitDialog类:
import android.app.Dialog; import android.content.Context; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.LinearLayout; import android.widget.TextView; import com.baidu.idl.main.facesdk.gatelibrary.R; public class WaitDialog { Dialog loadingDialog = null; String msg = ""; Context context = null; TextView tipTextView; private WaitDialog(Context context, String msg) { this.context = context; this.msg = msg; LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(R.layout.dialog_loading, null);// 得到加载view LinearLayout layout = (LinearLayout) v .findViewById(R.id.dialog_loading_view);// 加载布局 tipTextView = (TextView) v.findViewById(R.id.tipTextView);// 提示文字 tipTextView.setText(msg);// 设置加载信息 loadingDialog = new Dialog(context, R.style.MyDialogStyle);// 创建自定义样式dialog loadingDialog.setCancelable(true); // 是否可以按“返回键”消失 loadingDialog.setCanceledOnTouchOutside(false); // 点击加载框以外的区域 loadingDialog.setContentView(layout, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));// 设置布局 loadingDialog.getLayoutInflater(); /** * 将显示Dialog的方法封装在这里面 */ Window window = loadingDialog.getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; window.setGravity(Gravity.CENTER); window.setAttributes(lp); window.setWindowAnimations(R.style.PopWindowAnimStyle); } public static WaitDialog getInstance(Context context, String msg) { return new WaitDialog(context, msg); } public void show() { loadingDialog.show(); } public void setTitle(String msg) { tipTextView.setText(msg); } /** * 关闭dialog */ public void closeDialog() { try { if (loadingDialog != null && loadingDialog.isShowing()) { loadingDialog.dismiss(); } } catch (Exception e) { throw e; } finally { loadingDialog = null; } } }
2.类中用到的图片资源我会放到csdn上提供下载.
上面类中用到的:
src\main\res\layout\dialog_loading.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialog_loading_view" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <LinearLayout android:layout_width="@dimen/dp_180" android:layout_height="@dimen/dp_60" android:background="@mipmap/loading_bg" android:gravity="center" android:orientation="horizontal"> <ProgressBar android:id="@+id/progressBar1" android:layout_width="@dimen/dp_30" android:layout_height="@dimen/dp_30" android:layout_gravity="center_vertical" android:indeterminateBehavior="repeat" android:indeterminateDrawable="@drawable/dialog_loading" android:indeterminateOnly="true" /> <TextView android:id="@+id/tipTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/dp_10" android:text="加载中..." android:textColor="#f0f0f0" android:textSize="@dimen/dp_15" /> </LinearLayout> </LinearLayout>
3.dialog_loading.xml文件中用到的图片
src\main\res\mipmap-xxhdpi\loading_bg.9.png
这个图片右键保存就能用.
4.然后layout下的dialog_loading.xml这个文件中用到的:
"@drawable/dialog_loading"
\src\main\res\drawable\dialog_loading.xml
<?xml version="1.0" encoding="utf-8"?> <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@mipmap/dialog_loading_img" android:pivotX="50%" android:pivotY="50%" /> <!-- 下面是转圈的 <?xml version="cx_1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/dialog_loading_img2" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" /> -->
5.然后\src\main\res\drawable\dialog_loading.xml 这个文件中用到的图片
src\main\res\mipmap-xxhdpi\dialog_loading_img.png
这个图片也可以右键保存使用.
6.然后layout下的dialog_loading.xml这个文件中的用到的dimen
"@dimen/dp_30"
\src\main\res\values\lay_x.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="dp_1">1dp</dimen> <dimen name="dp_2">2dp</dimen> <dimen name="dp_3">3dp</dimen> <dimen name="dp_4">4dp</dimen> <dimen name="dp_5">5dp</dimen> <dimen name="dp_6">6dp</dimen> <dimen name="dp_7">7dp</dimen> <dimen name="dp_8">8dp</dimen> <dimen name="dp_9">9dp</dimen> <dimen name="dp_10">10dp</dimen> <dimen name="dp_11">11dp</dimen> <dimen name="dp_12">12dp</dimen> <dimen name="dp_13">13dp</dimen> <dimen name="dp_14">14dp</dimen> <dimen name="dp_15">15dp</dimen> <dimen name="dp_16">16dp</dimen> <dimen name="dp_17">17dp</dimen> <dimen name="dp_18">18dp</dimen> <dimen name="dp_19">19dp</dimen> <dimen name="dp_20">20dp</dimen> <dimen name="dp_21">21dp</dimen> <dimen name="dp_22">22dp</dimen> <dimen name="dp_23">23dp</dimen> <dimen name="dp_24">24dp</dimen> <dimen name="dp_25">25dp</dimen> <dimen name="dp_26">26dp</dimen> <dimen name="dp_27">27dp</dimen> <dimen name="dp_28">28dp</dimen> <dimen name="dp_29">29dp</dimen> <dimen name="dp_30">30dp</dimen> <dimen name="dp_31">31dp</dimen> <dimen name="dp_32">32dp</dimen> <dimen name="dp_33">33dp</dimen> <dimen name="dp_34">34dp</dimen> <dimen name="dp_35">35dp</dimen> <dimen name="dp_36">36dp</dimen> <dimen name="dp_37">37dp</dimen> <dimen name="dp_38">38dp</dimen> <dimen name="dp_39">39dp</dimen> <dimen name="dp_40">40dp</dimen> <dimen name="dp_41">41dp</dimen> <dimen name="dp_42">42dp</dimen> <dimen name="dp_43">43dp</dimen> <dimen name="dp_44">44dp</dimen> <dimen name="dp_45">45dp</dimen> <dimen name="dp_46">46dp</dimen> <dimen name="dp_47">47dp</dimen> <dimen name="dp_48">48dp</dimen> <dimen name="dp_49">49dp</dimen> <dimen name="dp_50">50dp</dimen> <dimen name="dp_51">51dp</dimen> <dimen name="dp_52">52dp</dimen> <dimen name="dp_53">53dp</dimen> <dimen name="dp_54">54dp</dimen> <dimen name="dp_55">55dp</dimen> <dimen name="dp_56">56dp</dimen> <dimen name="dp_57">57dp</dimen> <dimen name="dp_58">58dp</dimen> <dimen name="dp_59">59dp</dimen> <dimen name="dp_60">60dp</dimen> <dimen name="dp_61">61dp</dimen> <dimen name="dp_62">62dp</dimen> <dimen name="dp_63">63dp</dimen> <dimen name="dp_64">64dp</dimen> <dimen name="dp_65">65dp</dimen> <dimen name="dp_66">66dp</dimen> <dimen name="dp_67">67dp</dimen> <dimen name="dp_68">68dp</dimen> <dimen name="dp_69">69dp</dimen> <dimen name="dp_70">70dp</dimen> <dimen name="dp_71">71dp</dimen> <dimen name="dp_72">72dp</dimen> <dimen name="dp_73">73dp</dimen> <dimen name="dp_74">74dp</dimen> <dimen name="dp_75">75dp</dimen> <dimen name="dp_76">76dp</dimen> <dimen name="dp_77">77dp</dimen> <dimen name="dp_78">78dp</dimen> <dimen name="dp_79">79dp</dimen> <dimen name="dp_80">80dp</dimen> <dimen name="dp_81">81dp</dimen> <dimen name="dp_82">82dp</dimen> <dimen name="dp_83">83dp</dimen> <dimen name="dp_84">84dp</dimen> <dimen name="dp_85">85dp</dimen> <dimen name="dp_86">86dp</dimen> <dimen name="dp_87">87dp</dimen> <dimen name="dp_88">88dp</dimen> <dimen name="dp_89">89dp</dimen> <dimen name="dp_90">90dp</dimen> <dimen name="dp_91">91dp</dimen> <dimen name="dp_92">92dp</dimen> <dimen name="dp_93">93dp</dimen> <dimen name="dp_94">94dp</dimen> <dimen name="dp_95">95dp</dimen> <dimen name="dp_96">96dp</dimen> <dimen name="dp_97">97dp</dimen> <dimen name="dp_98">98dp</dimen> <dimen name="dp_99">99dp</dimen> <dimen name="dp_100">100dp</dimen> <dimen name="dp_101">101dp</dimen> <dimen name="dp_102">102dp</dimen> <dimen name="dp_103">103dp</dimen> <dimen name="dp_104">104dp</dimen> <dimen name="dp_105">105dp</dimen> <dimen name="dp_106">106dp</dimen> <dimen name="dp_107">107dp</dimen> <dimen name="dp_108">108dp</dimen> <dimen name="dp_109">109dp</dimen> <dimen name="dp_110">110dp</dimen> <dimen name="dp_111">111dp</dimen> <dimen name="dp_112">112dp</dimen> <dimen name="dp_113">113dp</dimen> <dimen name="dp_114">114dp</dimen> <dimen name="dp_115">115dp</dimen> <dimen name="dp_116">116dp</dimen> <dimen name="dp_117">117dp</dimen> <dimen name="dp_118">118dp</dimen> <dimen name="dp_119">119dp</dimen> <dimen name="dp_120">120dp</dimen> <dimen name="dp_121">121dp</dimen> <dimen name="dp_122">122dp</dimen> <dimen name="dp_123">123dp</dimen> <dimen name="dp_124">124dp</dimen> <dimen name="dp_125">125dp</dimen> <dimen name="dp_126">126dp</dimen> <dimen name="dp_127">127dp</dimen> <dimen name="dp_128">128dp</dimen> <dimen name="dp_129">129dp</dimen> <dimen name="dp_130">130dp</dimen> <dimen name="dp_131">131dp</dimen> <dimen name="dp_132">132dp</dimen> <dimen name="dp_133">133dp</dimen> <dimen name="dp_134">134dp</dimen> <dimen name="dp_135">135dp</dimen> <dimen name="dp_136">136dp</dimen> <dimen name="dp_137">137dp</dimen> <dimen name="dp_138">138dp</dimen> <dimen name="dp_139">139dp</dimen> <dimen name="dp_140">140dp</dimen> <dimen name="dp_141">141dp</dimen> <dimen name="dp_142">142dp</dimen> <dimen name="dp_143">143dp</dimen> <dimen name="dp_144">144dp</dimen> <dimen name="dp_145">145dp</dimen> <dimen name="dp_146">146dp</dimen> <dimen name="dp_147">147dp</dimen> <dimen name="dp_148">148dp</dimen> <dimen name="dp_149">149dp</dimen> <dimen name="dp_150">150dp</dimen> <dimen name="dp_151">151dp</dimen> <dimen name="dp_152">152dp</dimen> <dimen name="dp_153">153dp</dimen> <dimen name="dp_154">154dp</dimen> <dimen name="dp_155">155dp</dimen> <dimen name="dp_156">156dp</dimen> <dimen name="dp_157">157dp</dimen> <dimen name="dp_158">158dp</dimen> <dimen name="dp_159">159dp</dimen> <dimen name="dp_160">160dp</dimen> <dimen name="dp_161">161dp</dimen> <dimen name="dp_162">162dp</dimen> <dimen name="dp_163">163dp</dimen> <dimen name="dp_164">164dp</dimen> <dimen name="dp_165">165dp</dimen> <dimen name="dp_166">166dp</dimen> <dimen name="dp_167">167dp</dimen> <dimen name="dp_168">168dp</dimen> <dimen name="dp_169">169dp</dimen> <dimen name="dp_170">170dp</dimen> <dimen name="dp_171">171dp</dimen> <dimen name="dp_172">172dp</dimen> <dimen name="dp_173">173dp</dimen> <dimen name="dp_174">174dp</dimen> <dimen name="dp_175">175dp</dimen> <dimen name="dp_176">176dp</dimen> <dimen name="dp_177">177dp</dimen> <dimen name="dp_178">178dp</dimen> <dimen name="dp_179">179dp</dimen> <dimen name="dp_180">180dp</dimen> <dimen name="dp_181">181dp</dimen> <dimen name="dp_182">182dp</dimen> <dimen name="dp_183">183dp</dimen> <dimen name="dp_184">184dp</dimen> <dimen name="dp_185">185dp</dimen> <dimen name="dp_186">186dp</dimen> <dimen name="dp_187">187dp</dimen> <dimen name="dp_188">188dp</dimen> <dimen name="dp_189">189dp</dimen> <dimen name="dp_190">190dp</dimen> <dimen name="dp_191">191dp</dimen> <dimen name="dp_192">192dp</dimen> <dimen name="dp_193">193dp</dimen> <dimen name="dp_194">194dp</dimen> <dimen name="dp_195">195dp</dimen> <dimen name="dp_196">196dp</dimen> <dimen name="dp_197">197dp</dimen> <dimen name="dp_198">198dp</dimen> <dimen name="dp_199">199dp</dimen> <dimen name="dp_200">200dp</dimen> <dimen name="dp_201">201dp</dimen> <dimen name="dp_202">202dp</dimen> <dimen name="dp_203">203dp</dimen> <dimen name="dp_204">204dp</dimen> <dimen name="dp_205">205dp</dimen> <dimen name="dp_206">206dp</dimen> <dimen name="dp_207">207dp</dimen> <dimen name="dp_208">208dp</dimen> <dimen name="dp_209">209dp</dimen> <dimen name="dp_210">210dp</dimen> <dimen name="dp_211">211dp</dimen> <dimen name="dp_212">212dp</dimen> <dimen name="dp_213">213dp</dimen> <dimen name="dp_214">214dp</dimen> <dimen name="dp_215">215dp</dimen> <dimen name="dp_216">216dp</dimen> <dimen name="dp_217">217dp</dimen> <dimen name="dp_218">218dp</dimen> <dimen name="dp_219">219dp</dimen> <dimen name="dp_220">220dp</dimen> <dimen name="dp_221">221dp</dimen> <dimen name="dp_222">222dp</dimen> <dimen name="dp_223">223dp</dimen> <dimen name="dp_224">224dp</dimen> <dimen name="dp_225">225dp</dimen> <dimen name="dp_226">226dp</dimen> <dimen name="dp_227">227dp</dimen> <dimen name="dp_228">228dp</dimen> <dimen name="dp_229">229dp</dimen> <dimen name="dp_230">230dp</dimen> <dimen name="dp_231">231dp</dimen> <dimen name="dp_232">232dp</dimen> <dimen name="dp_233">233dp</dimen> <dimen name="dp_234">234dp</dimen> <dimen name="dp_235">235dp</dimen> <dimen name="dp_236">236dp</dimen> <dimen name="dp_237">237dp</dimen> <dimen name="dp_238">238dp</dimen> <dimen name="dp_239">239dp</dimen> <dimen name="dp_240">240dp</dimen> <dimen name="dp_241">241dp</dimen> <dimen name="dp_242">242dp</dimen> <dimen name="dp_243">243dp</dimen> <dimen name="dp_244">244dp</dimen> <dimen name="dp_245">245dp</dimen> <dimen name="dp_246">246dp</dimen> <dimen name="dp_247">247dp</dimen> <dimen name="dp_248">248dp</dimen> <dimen name="dp_249">249dp</dimen> <dimen name="dp_250">250dp</dimen> <dimen name="dp_251">251dp</dimen> <dimen name="dp_252">252dp</dimen> <dimen name="dp_253">253dp</dimen> <dimen name="dp_254">254dp</dimen> <dimen name="dp_255">255dp</dimen> <dimen name="dp_256">256dp</dimen> <dimen name="dp_257">257dp</dimen> <dimen name="dp_258">258dp</dimen> <dimen name="dp_259">259dp</dimen> <dimen name="dp_260">260dp</dimen> <dimen name="dp_261">261dp</dimen> <dimen name="dp_262">262dp</dimen> <dimen name="dp_263">263dp</dimen> <dimen name="dp_264">264dp</dimen> <dimen name="dp_265">265dp</dimen> <dimen name="dp_266">266dp</dimen> <dimen name="dp_267">267dp</dimen> <dimen name="dp_268">268dp</dimen> <dimen name="dp_269">269dp</dimen> <dimen name="dp_270">270dp</dimen> <dimen name="dp_271">271dp</dimen> <dimen name="dp_272">272dp</dimen> <dimen name="dp_273">273dp</dimen> <dimen name="dp_274">274dp</dimen> <dimen name="dp_275">275dp</dimen> <dimen name="dp_276">276dp</dimen> <dimen name="dp_277">277dp</dimen> <dimen name="dp_278">278dp</dimen> <dimen name="dp_279">279dp</dimen> <dimen name="dp_280">280dp</dimen> <dimen name="dp_281">281dp</dimen> <dimen name="dp_282">282dp</dimen> <dimen name="dp_283">283dp</dimen> <dimen name="dp_284">284dp</dimen> <dimen name="dp_285">285dp</dimen> <dimen name="dp_286">286dp</dimen> <dimen name="dp_287">287dp</dimen> <dimen name="dp_288">288dp</dimen> <dimen name="dp_289">289dp</dimen> <dimen name="dp_290">290dp</dimen> <dimen name="dp_291">291dp</dimen> <dimen name="dp_292">292dp</dimen> <dimen name="dp_293">293dp</dimen> <dimen name="dp_294">294dp</dimen> <dimen name="dp_295">295dp</dimen> <dimen name="dp_296">296dp</dimen> <dimen name="dp_297">297dp</dimen> <dimen name="dp_298">298dp</dimen> <dimen name="dp_299">299dp</dimen> <dimen name="dp_300">300dp</dimen> <dimen name="dp_301">301dp</dimen> <dimen name="dp_302">302dp</dimen> <dimen name="dp_303">303dp</dimen> <dimen name="dp_304">304dp</dimen> <dimen name="dp_305">305dp</dimen> <dimen name="dp_306">306dp</dimen> <dimen name="dp_307">307dp</dimen> <dimen name="dp_308">308dp</dimen> <dimen name="dp_309">309dp</dimen> <dimen name="dp_310">310dp</dimen> <dimen name="dp_311">311dp</dimen> <dimen name="dp_312">312dp</dimen> <dimen name="dp_313">313dp</dimen> <dimen name="dp_314">314dp</dimen> <dimen name="dp_315">315dp</dimen> <dimen name="dp_316">316dp</dimen> <dimen name="dp_317">317dp</dimen> <dimen name="dp_318">318dp</dimen> <dimen name="dp_319">319dp</dimen> <dimen name="dp_320">320dp</dimen> <dimen name="x10">10dp</dimen> <dimen name="x12">12dp</dimen> <dimen name="x14">14dp</dimen> <dimen name="x16">16dp</dimen> <dimen name="x18">18dp</dimen> <dimen name="x20">20dp</dimen> <dimen name="x22">22dp</dimen> <dimen name="x24">24dp</dimen> <dimen name="x26">26dp</dimen> <dimen name="x28">28dp</dimen> <dimen name="x30">30dp</dimen> <dimen name="x40">40dp</dimen> <dimen name="x50">50dp</dimen> <dimen name="x60">60dp</dimen> <dimen name="x70">70dp</dimen> <dimen name="x80">80dp</dimen> </resources>
7.然后在WaitDilog类中,用到的
dialog_loading_view
src\main\res\layout\dialog_confrim.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/dialog_loading_view" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/x30" android:background="@drawable/bg_bai_r4" android:orientation="vertical"> <TextView android:id="@+id/dialog_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:paddingTop="@dimen/x40" android:paddingBottom="@dimen/x40" android:text="确定退出测量?" android:textColor="@color/hei" android:textSize="@dimen/x16"> </TextView> <TextView android:layout_width="match_parent" android:layout_height="0.5dp" android:background="@color/hui"> </TextView> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/dialog_confirm_bt" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:padding="@dimen/x20" android:text="确定" android:textColor="@color/main_select" android:textSize="@dimen/x16"> </TextView> <TextView android:layout_width="0.5dp" android:layout_height="match_parent" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:background="@color/hui" tools:ignore="Suspicious0dp"></TextView> <TextView android:id="@+id/dialog_cancel_bt" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:padding="@dimen/x20" android:text="取消" android:textSize="@dimen/x16"> </TextView> </LinearLayout> </LinearLayout> </LinearLayout>
8.然后在src\main\res\layout\dialog_confrim.xml中用到的:
@drawable/bg_bai_r4
src\main\res\drawable\bg_bai_r4.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="@color/white" /> <!-- 圆角的半径 --> <corners android:radius="15dp" /> </shape> </item> </layer-list>
用到的dimen
"@dimen/x40" 已经有了上面.
9.然后用到的color
"@color/hei"
\src\main\res\values\colors.xml
<?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2018 Baidu, Inc. All Rights Reserved. --> <resources> <color name="gate_FF">#</color> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color> <color name="buttonColor">#FF6600</color> <color name="white">#FFFFFF</color> <color name="gate_white">#FFFFFF</color> <color name="black">#000000</color> <color name="blue">#00BFFF</color> <color name="buttonBg">#016838</color> <color name="red">#FF0033</color> <color name="gate_background">#</color> <color name="bottom_font_color">#</color> <color name="colorLine">#</color> <color name="attribute_title">#</color> <!--<color name="buttonBg">#FF009688</color>--> <color name="start_blue">#FF0DC6FF</color> <color name="activition_color">#</color> <color name="activition_view">#</color> <color name="activition_red">#F34B56</color> <color name="activition_on">#</color> <color name="buttom_title">#</color> <color name="off_view">#</color> <color name="transparent">#00000000</color> <color name="hui_color">#</color> <!-- <color name="colorPrimary">#008577</color>--> <!-- <color name="colorPrimaryDark">#00574B</color>--> <!-- <color name="colorAccent">#D81B60</color>--> <color name="bai">#FFFFFF</color> <color name="hei9">#</color> <color name="hei">#</color> <color name="hei3">#</color> <color name="lan">#4977fc</color> <color name="hong">#fc494c</color> <color name="dhlan">#1b76b3</color> <color name="bghui">#eeefef</color> <color name="qing">#da45ff57</color> <color name="huang">#f29327</color> <color name="background">#f8f8f8</color> <color name="partLine">#e5e5e5</color> <color name="master">#7370aa</color> <color name="second">#8d77df</color> <color name="lowest">#aa8ee4</color> <color name="lower">#00c1e4</color> <color name="stand">#a7cb40</color> <color name="higher">#fbc13d</color> <color name="highest">#f74142</color> <color name="sufficient">#3ea42c</color> <!--扫描二维码--> <color name="contents_text">#ff000000</color> <color name="encode_view">#ffffffff</color> <color name="possible_result_points">#c0ffbd21</color> <color name="result_minor_text">#ffc0c0c0</color> <color name="result_points">#c099cc00</color> <color name="result_text">#ffffffff</color> <color name="result_view">#b0000000</color> <color name="status_text">#ffffffff</color> <!-- <color name="transparent">#00000000</color>--> <color name="viewfinder_laser">#ffcc0000</color> <color name="viewfinder_mask">#</color> <color name="main_select">#1daa8d</color> <color name="main_select_no">#72777c</color> <color name="hong_real">#ff0000</color> <color name="hong_d5">#D54431</color> <color name="hong_f8">#F8786F</color> <color name="hei_f2">#f2f2f2</color> <color name="hei_f8">#f8f8f8</color> <color name="hei_ec">#ececec</color> <color name="hei_c7">#c7c7c7</color> <color name="hei_f9">#f9f9f9</color> <color name="hei_e8">#e8e8e8</color> <color name="hei_d7">#d7d7d7</color> <color name="hei_bc">#bcbcbc</color> <color name="hui_fa">#fafafa</color> <color name="hui_ea">#EAEAEA</color> <color name="huang_real">#ffa337</color> <color name="huang_ff">#fff4d5</color> <color name="huang_f5">#fffcf5</color> <color name="pay_bg">#f2f2f2</color> <color name="login_bg">#f4f7fa</color> <color name="login_edit_bg">#eeeeee</color> <color name="login_submit">#19aa8d</color> <color name="hei6">#</color> <color name="hui">#eeeeee</color> <color name="hui_48">#</color> <color name="white_blue">#b8f7e0</color> </resources>
10.然后在类WaitDialog中
R.style.MyDialogStyle
src\main\res\values\styles.xml
<resources> <style name="DefaultDialog" parent="android:style/Theme.Dialog"> <item name="android:background">#00000000</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> </style> <style name="Theme_NoTitle" parent="android:style/Theme.NoTitleBar.Fullscreen"> <item name="android:windowFrame">@null</item> <item name="android:windowContentOverlay">@null</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">false</item> </style> <style name="Theme_Translucent" parent="android:style/Theme.NoTitleBar.Fullscreen"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowFrame">@null</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:backgroundDimEnabled">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowFullscreen">false</item> </style> <style name="Theme_Fullscreen" parent="android:style/Theme.NoTitleBar.Fullscreen"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowFrame">@null</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:backgroundDimEnabled">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowFullscreen">true</item> </style> <style name="ImportDialog" parent="android:style/Theme.Dialog"> <item name="android:background">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> </style> <style name="SettingMainTitle"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_alignParentTop">true</item> <item name="android:layout_marginLeft">10dp</item> <item name="android:textColor">#000000</item> <item name="android:textSize">20sp</item> </style> <style name="SettingMainExplain"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_marginTop">5dp</item> <item name="android:layout_marginLeft">75dp</item> <item name="android:textColor">#016838</item> <item name="android:textSize">16sp</item> <item name="android:layout_alignParentTop">true</item> </style> <style name="SettingMainBlackPoint"> <item name="android:layout_width">5dp</item> <item name="android:layout_height">5dp</item> <item name="android:layout_centerVertical">true</item> <item name="android:layout_marginLeft">60dp</item> <item name="android:background">#000000</item> </style> <style name="TipDialog" parent="android:style/Theme.Dialog"> <item name="android:background">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> </style> <style name="configTextStyle"> <item name="android:textSize">20sp</item> <item name="android:layout_marginLeft">18dp</item> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_gravity">center_vertical</item> <item name="android:textColor">#ffffff</item> </style> <style name="configTextStyleTwo"> <item name="android:layout_marginLeft">15dp</item> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_gravity">center_vertical</item> <item name="android:textColor">#</item> <item name="android:textSize">14sp</item> </style> <style name="configViewtyle"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">30dp</item> </style> <style name="gate_face_detection"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">22.5dp</item> </style> <style name="configInnerImageLayout"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">match_parent</item> <item name="android:gravity">right</item> </style> <style name="configInnerImage"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_marginRight">15dp</item> <item name="android:layout_gravity">center_vertical</item> <item name="android:background">@mipmap/icon_setting_arrow</item> </style> <style name="configLinerView"> <item name="android:layout_width">550dp</item> <item name="android:layout_height">3dp</item> <item name="android:layout_gravity">center</item> <item name="android:background">#000000</item> </style> <style name="configPopupWindow"> <item name="android:windowEnterAnimation">@anim/sr_config_popupwindow_show_anim</item> <item name="android:windowExitAnimation">@anim/sr_config_popupwindow_hide_anim</item> </style> <style name="driverTextView"> <item name="android:singleLine">true</item> </style> <style name="MyEditText" parent="Theme.AppCompat.Light"> <item name="colorControlNormal">#</item> <item name="colorControlActivated">#ffffff</item> </style> <style name="MyEditTexterror" parent="Theme.AppCompat.Light"> <item name="colorControlNormal">#F34B56</item> <item name="colorControlActivated">#</item> </style> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="MyDialogStyle"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:backgroundDimEnabled">true</item> </style> <!-- popup window 显示消失动画--> <style name="PopWindowAnimStyle"> <item name="android:windowShowAnimation">@anim/dialog_enter</item> <!-- 指定显示的动画xml --> <item name="android:windowHideAnimation">@anim/dialog_exit</item> <!-- 指定消失的动画xml --> </style> <!-- 弹出框 --> <style name="Theme.AppCompat.Dialog.Alertblue" parent="Base.Theme.AppCompat.Dialog.Alert"> <item name="colorPrimary">@color/lan</item> <item name="windowNoTitle">true</item> </style> </resources>
11.然后就去使用就可以了
使用的时候,加上下面这些代码就可以了
private WaitDialog waitDialog; public Integer dialogState = 0; //这个是个标志,没有什么具体作用,如果你希望通过这个标志来判断当前弹出框是否正在显示就可以用上 public void showDialog(Context context, String msg) { if (waitDialog != null) { waitDialog.closeDialog(); } waitDialog = WaitDialog.getInstance(context, msg); waitDialog.show(); dialogState = 2; //开着是2 } public void closeDialog() { if (waitDialog != null) { waitDialog.closeDialog(); dialogState = 1; //关闭是1 } }
12.这里我使用的时候,是在BaseApplication类中使用的
package com.baidu.idl.main.facesdk.activity; import android.annotation.TargetApi; import android.app.Application; import android.content.Context; import android.content.SharedPreferences; import android.os.Build; import com.baidu.idl.main.facesdk.utils.DeviceFinal; import com.baidu.idl.main.facesdk.utils.WaitDialog; import com.qn.device.listener.QNResultCallback; import com.qn.device.out.QNBleApi; public class BaseApplication extends Application { static Context _context; private static String PREF_NAME = "ydy_store"; private String token; public Integer dialogState = 0; public String getToken() { return token; } public void setToken(String token) { this.token = token; } /** * Context base application. * * @return the base application */ public static synchronized BaseApplication context() { return (BaseApplication) _context; } /** * Gets preferences. * * @return the preferences */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static SharedPreferences getPreferences() { return context().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); } /** * On create. */ @Override public void onCreate() { super.onCreate(); QNBleApi mQNBleApi = QNBleApi.getInstance(this); String encryptPath = "file:///android_asset/.qn"; mQNBleApi.initSdk(DeviceFinal.QN_APPID, encryptPath, new QNResultCallback() { @Override public void onResult(int code, String msg) { System.out.println("初始化" + code + ":" + msg); } }); _context = getApplicationContext(); // ToastApp.initToastUtils(_context); CrashHandler crashHandler = CrashHandler.getInstance(); crashHandler.init(_context); //初始化Context // ContextHelper.getInstance().init(this); } private WaitDialog waitDialog; public void showDialog(Context context, String msg) { if (waitDialog != null) { waitDialog.closeDialog(); } waitDialog = WaitDialog.getInstance(context, msg); waitDialog.show(); dialogState = 2; //开着是2 } public void closeDialog() { if (waitDialog != null) { waitDialog.closeDialog(); dialogState = 1; //关闭是1 } } }
这个是我的BaseApplication类,可以看到我在里面加上了一个showDialog和closeDialog,其实就是调用的WaitDialog这个类.
13.然后使用的时候:
BaseApplication.context().showDialog(FaceBodyCheckActivity.this, "正在连接设备...");
这样就是显示这个等待框,然后
BaseApplication.context().closeDialog();
这样就是关闭等待框.
这个等待框带有蒙板效果.可以直接拿过去用.
今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。