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) {
}
}
对于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 标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获得 AlertDialog 标题?


基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01