gpt4 book ai didi

android - 如何获取 AlertDialog 标题?

转载 作者:可可西里 更新时间:2023-11-01 18:43:51 26 4
gpt4 key购买 nike

我试图获取消息并且下面的代码行有效:

TextView dialogMessage = (TextView)dialogObject.findViewById(android.R.id.message);

但是当我尝试使用以下行获取标题时,它返回 null

TextView dialogTitle = (TextView)dialogObject.findViewById(android.R.id.tittle);

最佳答案

我检查了AlertDialog 的代码。在内部,它们使用 R.id.alertTitle 来初始化 AlertDialog 标题的 TextView。您可以使用 getIdentifier 来检索它:

int titleId = getResources().getIdentifier( "alertTitle", "id", "android" );
if (titleId > 0) {
TextView dialogTitle = (TextView) dialogObject.findViewById(titleId);
if (dialogTitle != null) {

}
}

编辑:对于AppCompatgetIdentifier 的第三个参数应该是您应用程序的包名。您可以使用 context.getPackageName()

检索后者

关于android - 如何获取 AlertDialog 标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29161994/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com