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 标题?
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
