如何获取AlertDialog标题? [英] How to get the AlertDialog title?
本文介绍了如何获取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) {
}
}
这篇关于如何获取AlertDialog标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文