Dialog的isShowing()方法一直返回為true
常見的Dialog,常用的isShowing方法,用此方法常判斷dialog是否正在顯示,但是有時發現dialog沒有顯示,此方法也是返回true,這就尷尬了。
取消顯示dialog的方法
一、點選返回按鈕或者點選dialog之外的螢幕
/**
* Called when the dialog has detected the user's press of the back
* key. The default implementation simply cancels the dialog (only if
* it is cancelable), but you can override this to do whatever you want.
*/
public void onBackPressed() {
if (mCancelable) {
cancel();
}
}
點選返回按鈕,最後呼叫了cancel的方法;
/**
* Called when a touch screen event was not handled by any of the views
* under it. This is most useful to process touch events that happen outside
* of your window bounds, where there is no view to receive it.
*
* @param event The touch screen event being processed.
* @return Return true if you have consumed the event, false if you haven't.
* The default implementation will cancel the dialog when a touch
* happens outside of the window bounds.
*/
public boolean onTouchEvent(@NonNull MotionEvent event) {
if (mCancelable && mShowing && mWindow.shouldCloseOnTouch(mContext, event)) {
cancel();
return true;
}
return false;
}
點選螢幕之外最後也是呼叫cancel方法
二、看看cancel()方法
/**
* Cancel the dialog. This is essentially the same as calling {@link #dismiss()}, but it will
* also call your {@link DialogInterface.OnCancelListener} (if registered).
*/
@Override
public void cancel() {
if (!mCanceled && mCancelMessage != null) {
mCanceled = true;
// Obtain a new message so this dialog can be re-used
Message.obtain(mCancelMessage).sendToTarget();
}
dismiss();
}
看到原始碼,cancel方法最後還是呼叫了dismiss方法
三、看看dimiss()方法
/**
* Dismiss this dialog, removing it from the screen. This method can be
* invoked safely from any thread. Note that you should not override this
* method to do cleanup when the dialog is dismissed, instead implement
* that in {@link #onStop}.
*/
@Override
public void dismiss() {
if (Looper.myLooper() == mHandler.getLooper()) {
dismissDialog();
} else {
mHandler.post(mDismissAction);
}
}
看到原始碼,dismiss()會呼叫dismissDialog()方法
四、看看dismissDialog()方法
void dismissDialog() {
if (mDecor == null || !mShowing) {
return;
}
if (mWindow.isDestroyed()) {
Log.e(TAG, "Tried to dismissDialog() but the Dialog's window was already destroyed!");
return;
}
try {
mWindowManager.removeViewImmediate(mDecor);
} finally {
if (mActionMode != null) {
mActionMode.finish();
}
mDecor = null;
mWindow.closeAllPanels();
onStop();
mShowing = false;
sendDismissMessage();
}
}
看到原始碼,最後將mShowing = false;
五、再看看hide()方法
/**
* Hide the dialog, but do not dismiss it.
*/
public void hide() {
if (mDecor != null) {
mDecor.setVisibility(View.GONE);
}
}
可以看到並沒有將mShowing賦值。所以呼叫hide方法,隱藏dialog但是isShowing方法還是會返回true。
總結:
1.點選返回按鍵或者點選dialog之外的螢幕->cancel()->dismiss()->dismissDialog->mShowing = false;
此時dialog沒有顯示, isShowing方法返回false;
2.呼叫hide()->dialog隱藏,mShowing依然是true;
此時dialog沒有顯示,isShowing方法返回true;
相關推薦
Dialog的isShowing()方法一直返回為true
常見的Dialog,常用的isShowing方法,用此方法常判斷dialog是否正在顯示,但是有時發現dialog沒有顯示,此方法也是返回true,這就尷尬了。 取消顯示dialog的方法
奇怪的Java題:為什麼1000 == 1000返回為False,而100 == 100會返回為True?
這是我們今天要討論的話題,因為我覺得它非常的有趣。 如果你執行如下程式碼: 1 2 3 4 Integer a = 1000, b = 1000; System.out.println(a == b);//1 Integer c =
Python3基礎 filter 第一個參數為NONE時 結果只返回為True的對象
4.5 main 實踐 pycha .cn download class eps data ? ???????Python : 3.7.0 ?????????OS : Ubuntu 18.04.1 LTS ????????IDE : PyCharm 2018.2.4 ?
mybatis Mapper 中resultType使用方法及返回值為Map的寫法 mybatis學習(七)——resultType解析
mybatis學習(七)——resultType解析 resultType是sql對映檔案中定義返回值型別,返回值有基本型別,物件型別,List型別,Map型別等。現總結一下再解釋 總結: resultType: 1、基本型別 :resultType=基本型別 2、Lis
ViVo手機無法安裝run出來的apk-testOnly run出來一直為true
說明 點選Android Studio上面的綠色Run按鈕,出來的debug apk的AndroidManifest.xml的android:testOnly="true",即使修改為false也沒有用。可以使用Build-Build APK(s)來打出testOnly為f
關於PHP中PDO抽象層,採用rowCount();方法出現返回結果為0的解決方案
在學PHP的過程中,遇到一些問題,但不是全部都能夠順利得到解決,就在PDO抽象層,採用rowCount();方法出現數據能夠正常查詢出來的情況下返回結果為0,在網上搜了一天,沒有一個具體的說明和解決方案,很多朋友在問,但卻沒有人回答,因此在這裡稍微說說具體的情況及最終的解決
關於Spring的JdbcTemplate批量更新batchUpdate()方法的返回值為-2的異常
近日在使用JdbcTemplate做大量的資料庫資料同步的工作,基本就是“從A庫查詢資料--生成CSV--解析成SQL插入B庫”這樣一個過程。因為使用的是JdbcTemplate,所以在將資料匯入B庫時採用的是“先批量刪,再批量插入”的策略。如果B庫有相同主鍵的記錄,則
Spring為屬性注入某個類的常量或方法的返回值
spring提供了filed的值注入和method的返回值注入。 1、Field值的注入 filed值注入需要使用org.springframework.beans.factory.config.FieldRetrievingFactoryBean來獲取類的靜態變數。 例如
setOnTouchEvent 設定返回值為true 和 false的區別
View 類的 setOnTouchListener(OnTouchListener l)事件監聽,在構造 OnTouchListener 物件時需要重寫 onTouch(…)方法,這個方法的返回值是布林型別, 剛開始我按預設給定的返回值 false執行,發現
自定義View通過findviewbyid返回為null解決方法
findviewbyid 返回為null,這個問題一般說明想要找的view沒有在對應的layout上面。 今天遇到一個同樣的問題,但是確定view已經在layout上,但是仍然返回為null。雖然最終找到了問題原因,但是過程艱辛。 具體程式碼如下 MainAct
Go語言中json.Marshal()一直返回[123 125]的解決方法
Go語言中對結構體進行json.Marshal()一直返回[123 125]即“{}”,原因是go中是否可匯出是根據名字首字母是否大寫來確定的,如果結構體某欄位的首字母為小寫則不可匯出,例子如下(注意Student內欄位首字母的大小寫):不可匯出:type Student s
ajax得到後端數據一直提示為[object Object]解決方法
string alert add req ping ava function check com 前段ajax <script type="text/javascript"> function requestJson() {
springmvc 註解式開發 處理器方法的返回值
pri ajax mvc img 返回值 -1 分享 alt spring 1.返回void -Ajax請求 後臺: 前臺: springmvc 註解式開發 處理器方法的返回值
jquery---checked,indeterminate都為true沖突
element query eterm inpu nts con 問題 term () 問題描述: 放checkbox的checked,indeterminate都為true時 $("input[type=che
MySQL——修改root密碼的4種方法(以windows為例)
ron 情況 登錄 使用 方法 命令 ont demo root密碼 MySQL——修改root密碼的4種方法(以windows為例) 來自:http://www.jb51.net/article/39454.htm 本文以windows為例為大家詳細介紹下MySQL
linux 本地賬號密碼無法登陸(shell可以登錄),一直返回 登陸的login界面
語句 發現 image ima 本地 更改 描述 分析 模式 今天我在我虛擬機測試的時候遇到了一個問題。登陸centos一直是返回login,賬號和密碼沒錯,我也換了兩個用戶。 1.問題描述 我正常的輸入用戶名和密碼 錯誤提示截圖:返回登陸界面
Web API 方法的返回類型、格式器、過濾器
lca asc .net nbsp tin 過濾 col 數據 www 一、Action方法的返回類型 a) 操作方法的返回類型有四種:void、簡單或復雜類型、HttpResponseMessage類型、IHttpActionResult類型。 b) 如果返回類型為voi
數組常用的方法和返回值
末尾 splice for slice 拼接 test map shift 全部 push:向數組的末尾增加一項 返回值是數組的新長度unshift:向數組開頭增加一項 返回值是數組的新長度pop:刪除數組的末尾項 返回值是刪除的數組項shift:刪除數組開頭項 返回被刪除
linux 本地賬號密碼無法登陸,一直返回 登陸的login界面
linux 登陸問題登陸redhat一直是返回login,賬號和密碼沒錯通過ssh crt類的軟件遠程連接系統然後更改文件 vi /etc/pam.d/login 把 :session required /lib/security/pam_limits.so 更改為:session required
Python實現groupBy函數。grpby = groupBy(lambda x: x%2 is 1),grpby([1, 2, 3])的結果為{True: [1, 3], False: [2]}
結果 false n) pen als 不存在 def lam nbsp def groupBy(fn): def go(lst): m = {} for v in lst: m[fn(v)].append(v) if m.get(fn(v