Android開發(fā)解決popupWindow重疊報錯問題
在popupWindow里面再彈出popupWindow的時候會報這樣的錯誤
ERROR/AndroidRuntime(888): android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRoot$W@44ef1b68 is not valid; is your activity running?
報錯的意思大概就是說依賴的Activity沒了。
解決方法1
不要在當(dāng)前的popupWindow里面繼續(xù)show一個popupWindow,應(yīng)該寫一個接口回調(diào)到Activity里面進行show,
解決方法2
如果只是簡單的彈窗提醒的話,把第二次彈出的popupwindows改為Toast,
public class VerifySuccessDialog extends Toast {
public VerifySuccessDialog(Context context) {
super(context);
//設(shè)置toast的View
setView(LayoutInflater.from(context).inflate(R.layout.include_popwindow_verify, null));
//彈出位置
setGravity(Gravity.CENTER, 0, 0);
//時長
setDuration(Toast.LENGTH_SHORT);
}
}
用的地方就
new VerifySuccessDialog(mActivity).show();
解決方法3
第二次彈窗改為Dialog,設(shè)置dialog的style,在Style.xml添加
<style name="VerifyDialog" parent="@android:style/Theme.Holo.Dialog.NoActionBar">
<item name="android:windowBackground">@drawable/trans</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowSoftInputMode">adjustPan</item>
</style>
定義一個Dialog類
public class VerifySuccessDialog extends Dialog {
//用來設(shè)置時間自動關(guān)閉
private int showTime;
public VerifySuccessDialog(Context context) {
super(context, R.style.VerifyDialog);
setContentView(R.layout.include_popwindow_verify);
}
public int getShowTime() {
return showTime;
}
public void setShowTime(int showTime) {
this.showTime = showTime;
}
}
用就直接:
VerifySuccessDialog dialog = new VerifySuccessDialog(mActivity);
顯示的地方
dialog.show();
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
Android Studio 4.0 新功能中的Live Layout Inspector詳解
這篇文章主要介紹了Android Studio 4.0 新功能中的Live Layout Inspector,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-06-06
Android提高之SurfaceView的基本用法實例分析
這篇文章主要介紹了Android提高之SurfaceView的基本用法,非常實用的功能,需要的朋友可以參考下2014-08-08
Android?LinearLayout快速設(shè)置每個item間隔
這篇文章主要介紹了Android?LinearLayout快速設(shè)置每個item間隔的相關(guān)資料,需要的朋友可以參考下2023-07-07

