gpt4 book ai didi

android对话框将图标设置为标题

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:36:18 25 4
gpt4 key购买 nike

我有这个对话框类,我想将图标设置为它的标题:

public class DialogMealInformation extends Dialog implements
android.view.View.OnClickListener {
Context context;
private TextView tv_information;
private Button b_ok;
private String information;

public DialogMealInformation(Context context, String information) {
// TODO Auto-generated constructor stub
super(context);
this.context = context;
this.information = information;
setContentView(R.layout.dialog_meal_information);
getWindow().setLayout(android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
setTitle("Info !");

initialize();
}

它是这样尝试的:

setTitle(R.layout.dialog_simple_header);

dialog_simple_header.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<TextView
android:id="@+id/tv_dialog_simple_header_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tv_information"
android:drawableLeft="@drawable/more_information" />

</LinearLayout>

但是之后的标题是“res/layout/dialog_simple_header.x”只是文本,没有出现图标,为什么,解决方案是什么,非常感谢

最佳答案

在任何按钮 单击或在您的onActivity 或您希望此对话框显示的任何地方执行此操作。请务必在 //

之后阅读我的评论
AlertDialog alertDialog = new AlertDialog.Builder(
this).create();
alertDialog.setTitle("TITLE"); // your dialog title
alertDialog.setMessage("Your message"); // a message above the buttons
alertDialog.setIcon(R.drawable.ic_home); // the icon besides the title you have to change it to the icon/image you have.
alertDialog.setButton("Got IT", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { // here you can add a method to the button clicked. you can create another button just by copying alertDialog.setButton("okay")
}

});
alertDialog.show();

帮我个忙把这个删了

    public DialogMealInformation(Context context, String information) {
// TODO Auto-generated constructor stub
super(context);
this.context = context;
this.information = information;
setContentView(R.layout.dialog_meal_information);
getWindow().setLayout(android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
setTitle("Info !");

initialize();
}

然后添加我的!

关于android对话框将图标设置为标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14925250/

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