我尝试获取该消息并且以下代码行有效:
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 标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!