Mar*_*oli 4 android android-dialog
我有这个对话框类,我想将图标设置为其标题:
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();
}
Run Code Online (Sandbox Code Playgroud)
它尝试这样:
setTitle(R.layout.dialog_simple_header);
Run Code Online (Sandbox Code Playgroud)
<?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>
Run Code Online (Sandbox Code Playgroud)
但之后的标题是"res/layout/dialog_simple_header.x"只是文字,没有出现图标,请问为什么,解决方案是什么,非常感谢
k0s*_*0sh 14
在任何button单击或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();
Run Code Online (Sandbox Code Playgroud)
帮我一个忙,删除它
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();
}
Run Code Online (Sandbox Code Playgroud)
并添加我的!
| 归档时间: |
|
| 查看次数: |
15017 次 |
| 最近记录: |