項目的熱更新用的bugly,不過一直都只是使用他自帶的升級彈窗。
不過UI小姐姐說彈窗太丑了,要自定義。
bugly有提供自定義UI的官方文檔:https://bugly.qq.com/docs/user-guide/advance-features-android-beta/?v=20160824161206#ui
不過關於自定義里並沒有講得很細致,是以為我可以憑快禿的腦袋猜出來叭。
官方文檔里有提到需要標注的5個tag:
可是並沒有說這五個tag都必須出現在布局中, 否則將顯示不出更新的信息
所以布局文件里不管有沒有用到這些,都要全部設置出來,比如我的布局文件里只用了標題和說明以及下載按鈕
但在布局文件里依然添加了另外兩個tag:
<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" />
噢還有就是彈窗的半透明背景需要自己在布局文件中設置。
一般是在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就是剛剛畫布局的類,把背景半透明就好了,至於這個類里的代碼就是先這樣,這樣,再那樣,就可以了(官方文檔里有)