問題描述
我嘗試獲取該消息并且以下代碼行有效:
I tried to get the message and the following line of code works:
TextView dialogMessage = (TextView)dialogObject.findViewById(android.R.id.message);
但是當(dāng)我嘗試使用以下行獲取標題時,它返回 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
的代碼.在內(nèi)部,他們使用 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
的第三個參數(shù)應(yīng)該是你的應(yīng)用的包名.您可以使用 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()
這篇關(guān)于如何獲得 AlertDialog 標題?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!