I have this dialog class and i want to set icon to its title:
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();
}
it tried like this:
setTitle(R.layout.dialog_simple_header);
<?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>
but the title after that was "res/layout/dialog_simple_header.x" just text, no icon is appear, why please , what is the solution , thanks alot
here is a dialog with custom theme and View
final Dialog dialog = new Dialog(mContext,android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.dialog_layout_third);
ImageView image = (ImageView) dialog.findViewById(R.id.image2);
//image.setImageResource(R.drawable.ic_launcher);
image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
dialog.setCancelable(false);
here i'm setting the theme to transparent and then i'm using dialog.SetContentView
to add the layout. in my layout i'm using only an imageview
and here is my layout for the dialog.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/onetimeedit"
android:visibility="visible"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/drag" />
</RelativeLayout>
</FrameLayout>
you can then add textView
as Title just add it to the layout. and or using dialog.setTitle("MyTitleShouldByHere");
hope my example clear it for you, and if that what you want please do accept the answer so other people can get it easy. thanks
Dialog.setTitle(int resId) is used if you wish to set the title text to a string resource.
What you are looking for is what you are already doing - setContentView. In your custom xml there make the title look like what you prefer, or - if you wish to set it at runtime, just get a reference to the ImageView and set it in code.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With