項目的熱更新用的bugly,不過一直都只是使用他自帶的升級彈窗。android
不過UI小姐姐說彈窗太醜了,要自定義。app
bugly有提供自定義UI的官方文檔:https://bugly.qq.com/docs/user-guide/advance-features-android-beta/?v=20160824161206#uiide
不過關於自定義裏並無講得很細緻,是覺得我能夠憑快禿的腦殼猜出來叭。佈局
官方文檔裏有提到須要標註的5個tag:ui
但是並無說這五個tag都必須出如今佈局中, 不然將顯示不出更新的信息this
因此佈局文件裏無論有沒有用到這些,都要所有設置出來,好比個人佈局文件裏只用了標題和說明以及下載按鈕spa
但在佈局文件裏依然添加了另外兩個tag:code
<TextView android:tag="beta_cancel_button" android:layout_width="0dp" android:layout_height="0dp" /> <TextView android:tag="beta_upgrade_info" android:layout_width="0dp" android:layout_height="0dp" />
噢還有就是彈窗的半透明背景須要本身在佈局文件中設置。blog
通常是在application類裏初始化bugly,在init以前先設置佈局文件接口
Beta.upgradeDialogLayoutId = R.layout.activity_upgrade;//注意這句要設置在bugly init以前 Bugly.init(this, Constants.APP_ID_BUGLY, false); Beta.upgradeListener = new UpgradeListener() { @Override public void onUpgrade(int ret, UpgradeInfo strategy, boolean isManual, boolean isSilence) { if (strategy != null) { L.e(TAG, "檢測到更新"); Intent i = new Intent(); i.setClass(getApplicationContext(), UpgradeActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); } else { L.e(TAG, "沒有更新"); } } }; /* 設置更新狀態回調接口 */ Beta.upgradeStateListener = new UpgradeStateListener() { @Override public void onUpgradeSuccess(boolean isManual) { L.e(TAG, "UPGRADE_SUCCESS"); } @Override public void onUpgradeFailed(boolean isManual) { L.e(TAG, "UPGRADE_FAILED"); } @Override public void onUpgrading(boolean isManual) { L.e(TAG, "UPGRADE_CHECKING"); } @Override public void onDownloadCompleted(boolean b) { } @Override public void onUpgradeNoVersion(boolean isManual) { L.e(TAG, "UPGRADE_NO_VERSION"); } };
跳轉的UpgradeActivity就是剛剛畫布局的類,把背景半透明就行了,至於這個類裏的代碼就是先這樣,這樣,再那樣,就能夠了(官方文檔裏有)