本文介紹了如何獲得 AlertDialog 標題?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我嘗試獲取該消息并且以下代碼行有效:
I tried to get the message and the following line of code works:
TextView dialogMessage = (TextView)dialogObject.findViewById(android.R.id.message);
但是當我嘗試使用以下行獲取標題時,它返回 null
But when I try to get the title using the following line it returns null
TextView dialogTitle = (TextView)dialogObject.findViewById(android.R.id.tittle);
推薦答案
我檢查了 AlertDialog
的代碼.在內部,他們使用 R.id.alertTitle
來初始化 AlertDialog
標題的 TextView
.您可以使用 getIdentifier
來檢索它:
I checked up the code of the AlertDialog
. Internally they use R.id.alertTitle
to initialize the AlertDialog
title's TextView
. You can use getIdentifier
to retrieve it:
int titleId = getResources().getIdentifier( "alertTitle", "id", "android" );
if (titleId > 0) {
TextView dialogTitle = (TextView) dialogObject.findViewById(titleId);
if (dialogTitle != null) {
}
}
對于AppCompat
,getIdentifier
的第三個參數應該是你的應用的包名.您可以使用 context.getPackageName()
for AppCompat
, the third argument of getIdentifier
should be the package name of your app. You can retrieve the latter with context.getPackageName()
這篇關于如何獲得 AlertDialog 標題?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!