您好,登錄后才能下訂單哦!
小編給大家分享一下Android自定義仿ios加載彈窗的示例分析,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
具體內(nèi)容如下
效果如下:
IosLoadDialog類(lèi)(可直接復(fù)制):
public class IosLoadDialog extends Dialog { public IosLoadDialog(Context context) { super(context, R.style.loading_dialog); initView(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode){ case KeyEvent.KEYCODE_BACK: if(IosLoadDialog.this.isShowing()) IosLoadDialog.this.dismiss(); break; } return true; } private void initView(){ setContentView(R.layout.dialog_loading); Animation animation = AnimationUtils.loadAnimation(getContext(), R.anim.load_animation); animation.setInterpolator(new LinearInterpolator()); findViewById(R.id.loading_dialog_img).startAnimation(animation); setCanceledOnTouchOutside(true); WindowManager.LayoutParams attributes = getWindow().getAttributes(); attributes.alpha=0.8f; getWindow().setAttributes(attributes); setCancelable(false); } }
R.layout.dialog_loading文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialog_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/tm" android:gravity="center" android:minHeight="60dp" android:minWidth="180dp" android:orientation="vertical" android:padding="10dp"> <LinearLayout android:layout_width="80dp" android:layout_height="80dp" android:background="@drawable/white_radian13" android:gravity="center" android:orientation="vertical"> <ImageView android:id="@+id/loading_dialog_img" android:layout_width="50dp" android:layout_height="50dp" android:scaleType="fitXY" android:src="@drawable/ic_svstatus_loading" /> </LinearLayout> </LinearLayout>
loading_dialog樣式:
<style name="loading_dialog" parent="android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowBackground">@color/tm</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> </style>
white_radian13白色透明圓角背景:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <solid android:color="#F7FBFD" /> <corners android:radius="13dp" /> </shape> </item> </layer-list>
然后奉上圖片ic_svstatus_loading.png:
最后使用:
public void showDialog(){ final IosLoadDialog iosLoadDialog = new IosLoadDialog(this); iosLoadDialog.show(); new Handler().postDelayed(new Runnable() { @Override public void run() { iosLoadDialog.dismiss(); } },1200); }
Android是一種基于Linux內(nèi)核的自由及開(kāi)放源代碼的操作系統(tǒng),主要使用于移動(dòng)設(shè)備,如智能手機(jī)和平板電腦,由美國(guó)Google公司和開(kāi)放手機(jī)聯(lián)盟領(lǐng)導(dǎo)及開(kāi)發(fā)。
看完了這篇文章,相信你對(duì)“Android自定義仿ios加載彈窗的示例分析”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。