设置标题和(职称)的图标自定义警告对话框 [英] Set title and (title) icon for a custom alert dialog
问题描述
我不设法设置一个既不是所有权,也不是一个(冠军)图标,我的自定义警告对话框。
我的code:
I don't manage to set a neither a title nor a (title) icon to my custom alert dialog. My code:
public class AddingFavoriteDialog extends AlertDialog {
private OnAddingFavoriteListener onAddingFavoriteListener;
private Context context;
private GeocodingManager geocodingManager;
private FavoritesActivity favoritesActivity;
public AddingFavoriteDialog(Context context, OnAddingFavoriteListener onAddingFavoriteListener) {
super(context, android.R.style.Theme_Dialog);
this.context = context;
this.onAddingFavoriteListener = onAddingFavoriteListener;
this.geocodingManager = new GeocodingManager(context);
this.favoritesActivity = (FavoritesActivity) context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.adding_favorite_dialog2);
setTitle("MYTITLE");
setIcon(R.drawable.star_gold);
}
我究竟做错了什么?我也试图通过调用设置 super.setTitle(MYTITLE);
在的onCreate()
以及在构造函数中。
What am i doing wrong? I also tried to set it by calling super.setTitle("MYTITLE");
in onCreate()
as well as in the constructor.
编辑:均匀 SET按钮(BUTTON_POSITIVE,context.getString(R.string.button_value_OK)
似乎不起作用。
新OnClickListener(){...}
推荐答案
使用的 的setView
而不是的setContentView
,因为的setContentView
替换一切 AlertDialog
,包括默认的标题栏和图标(和按钮等)。相反,的setView
只替换中间部分(该消息,如果你愿意)。
Use setView
instead of setContentView
, because setContentView
replaces everything in the AlertDialog
, including the default title bar and icon (and buttons etc.). Instead, setView
only replaces the middle part (the message, if you will).
使用 LayoutInflater
如果你需要。
Use LayoutInflater
if you need to.
这篇关于设置标题和(职称)的图标自定义警告对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!