[android-developers] Re: How is android's AlertDialog layout define?
On Mar 23, 12:27 pm, Lucius Fox lucius.fo...@gmail.com wrote: Can you please tell me where I can the layout xml file for theAlertDialog? I try to do a 'grep for 'alert1' in all the files in the source tree, it does not return anything. I believe it's frameworks/base/core/res/res/layout/alert_dialog.xml However, there are no elements named 'body. The structure of the xml file is: LinearLayout parentPanel LinearLayout topPanel LinearLayout title_template ImageView icon DialogTitle alertTitle ImageView titleDivider LinearLayout contentPanel ScrollView scrollView TextView message FrameLayout customPanel FrameLayout custom LinearLayout buttonPanel Button button1 Button button3 Button button2 I'm guessing the FrameLayout custom is the one you want, but android.R.id.custom didn't resolve, so I'm stuck. IMHO, if you need to customize an alert dialog beyond setting the title and message, maybe it's time to start thinking about just implementing your own, subclassed from Dialog. And speaking of which, anybody know anything about embedding links in the text of an AlertDialog? I tried adding a href=http://foo.com/docs/;online documentation/a to the string resource, and it displays correctly, but the user can't click it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How is android's AlertDialog layout define?
look at the api demos samples. there are plenty of nice examples there. 2009/4/17 Edward Falk ed.f...@gmail.com On Mar 23, 12:27 pm, Lucius Fox lucius.fo...@gmail.com wrote: Can you please tell me where I can the layout xml file for theAlertDialog? I try to do a 'grep for 'alert1' in all the files in the source tree, it does not return anything. I believe it's frameworks/base/core/res/res/layout/alert_dialog.xml However, there are no elements named 'body. The structure of the xml file is: LinearLayout parentPanel LinearLayout topPanel LinearLayout title_template ImageView icon DialogTitle alertTitle ImageView titleDivider LinearLayout contentPanel ScrollView scrollView TextView message FrameLayout customPanel FrameLayout custom LinearLayout buttonPanel Button button1 Button button3 Button button2 I'm guessing the FrameLayout custom is the one you want, but android.R.id.custom didn't resolve, so I'm stuck. IMHO, if you need to customize an alert dialog beyond setting the title and message, maybe it's time to start thinking about just implementing your own, subclassed from Dialog. And speaking of which, anybody know anything about embedding links in the text of an AlertDialog? I tried adding a href=http://foo.com/docs/;online documentation/a to the string resource, and it displays correctly, but the user can't click it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How is android's AlertDialog layout define?
LinearLayout android:orientation=vertical android:layout_width=fill_parent android:layout_height=wrap_content LinearLayout android:orientation=vertical android:id=@+id/ topPanel android:layout_width=fill_parent android:layout_height=wrap_content android:layout_marginLeft=14px android:layout_marginRight=14px LinearLayout android:orientation=horizontal android:layout_width=fill_parent android:layout_height=wrap_content android:layout_marginLeft=5px android:layout_marginTop=5px android:layout_marginRight=5px android:layout_marginBottom=5px ImageView android:id=@+id/icon android:layout_width=wrap_content android:layout_height=wrap_content /ImageView TextView android:layout_gravity=center_vertical android:id=@+id/ alertTitle android:layout_width=fill_parent android:layout_height=wrap_content :style=?android:attr/ textAppearanceMedium /TextView /LinearLayout /LinearLayout LinearLayout android:orientation=vertical android:id=@+id/ contentPanel android:layout_width=fill_parent android:layout_height=wrap_content android:layout_marginLeft=14px android:layout_marginRight=14px ScrollView android:id=@+id/scrollView android:layout_width=fill_parent android:layout_height=wrap_content TextView android:id=@+id/message android:padding=5px android:layout_width=fill_parent android:layout_height=wrap_content :style=?android:attr/ textAppearanceMedium /TextView /ScrollView /LinearLayout RelativeLayout android:id=@+id/buttonPanel android:layout_width=fill_parent android:layout_height=wrap_content android:layout_marginLeft=14px android:layout_marginRight=14px LinearLayout android:orientation=vertical android:id=@+id/separatorBottom android:background=@drawable/divider_horizontal_bright android:layout_width=fill_parent android:layout_height=1px android:layout_marginBottom=2px /LinearLayout Button android:id=@+id/button1 android:layout_width=wrap_content android:layout_height=wrap_content android:layout_below=@id/ separatorBottom android:layout_alignParentLeft=true /Button Button android:id=@+id/button3 android:layout_width=wrap_content android:layout_height=wrap_content android:layout_below=@id/ separatorBottom android:layout_centerHorizontal=true /Button Button android:id=@+id/button2 android:layout_width=wrap_content android:layout_height=wrap_content android:layout_below=@id/ separatorBottom android:layout_alignParentRight=true /Button /RelativeLayout /LinearLayout On Mar 23, 3:27 pm, Lucius Fox lucius.fo...@gmail.com wrote: Can you please tell me where I can the layout xml file for the AlertDialog? I try to do a 'grep for 'alert1' in all the files in the source tree, it does not return anything. Thanks for tips. On Sun, Mar 22, 2009 at 11:56 AM, Dianne Hackborn hack...@android.com wrote: The layout is an xml file, and an implementation detail. If you want to have your own kind of alert dialog, just subclass from Dialog and make it yourself. Given how customizable AlertDialog is (with the ability to stick in your own layouts and such), I think trying to do something beyond what it supports is probably best done as just a custom dialog. On Sat, Mar 21, 2009 at 11:56 PM, Lucius Fox lucius.fo...@gmail.com wrote: Hi, How is android's AlertDialog layout define? Is there a layout.xml file corresponding to the AlertDialog? I have looked at AlertDialog implementation, But i don't figure out how that is being layout (e.g. the location of the button, the location of text) Where are they defined? And how can I change that? Thank you. -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How is android's AlertDialog layout define?
Can you please tell me where I can the layout xml file for the AlertDialog? I try to do a 'grep for 'alert1' in all the files in the source tree, it does not return anything. Thanks for tips. On Sun, Mar 22, 2009 at 11:56 AM, Dianne Hackborn hack...@android.com wrote: The layout is an xml file, and an implementation detail. If you want to have your own kind of alert dialog, just subclass from Dialog and make it yourself. Given how customizable AlertDialog is (with the ability to stick in your own layouts and such), I think trying to do something beyond what it supports is probably best done as just a custom dialog. On Sat, Mar 21, 2009 at 11:56 PM, Lucius Fox lucius.fo...@gmail.com wrote: Hi, How is android's AlertDialog layout define? Is there a layout.xml file corresponding to the AlertDialog? I have looked at AlertDialog implementation, But i don't figure out how that is being layout (e.g. the location of the button, the location of text) Where are they defined? And how can I change that? Thank you. -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How is android's AlertDialog layout define?
The layout is an xml file, and an implementation detail. If you want to have your own kind of alert dialog, just subclass from Dialog and make it yourself. Given how customizable AlertDialog is (with the ability to stick in your own layouts and such), I think trying to do something beyond what it supports is probably best done as just a custom dialog. On Sat, Mar 21, 2009 at 11:56 PM, Lucius Fox lucius.fo...@gmail.com wrote: Hi, How is android's AlertDialog layout define? Is there a layout.xml file corresponding to the AlertDialog? I have looked at AlertDialog implementation, But i don't figure out how that is being layout (e.g. the location of the button, the location of text) Where are they defined? And how can I change that? Thank you. -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How is android's AlertDialog layout define?
usually your layout is defined in an xml file (in res/layout) and in your Java-like Android code you can reference it so: d.setContentView(R.layout.dialog_view); where d is an instance of AlertDialog. and dialog_view.xml could contain: ?xml version=1.0 encoding=utf-8? RelativeLayout xmlns:android=http://schemas.android.com/apk/res/ android android:layout_width=fill_parent android:layout_height=fill_parent !-- android:title=any title does not work -- TextView android:id=@+id/label android:layout_width=fill_parent android:layout_height=wrap_content android:text=The search is case sensitive:/ EditText android:id=@+id/entry android:layout_width=fill_parent android:layout_height=wrap_content android:background=@android:drawable/editbox_background android:layout_below=@id/label/ Button android:id=@+id/find android:layout_width=wrap_content android:layout_height=wrap_content android:layout_below=@id/entry android:layout_alignParentLeft=true android:layout_marginRight=10dip android:text=Find Next / Button android:id=@+id/cancel_search android:layout_width=wrap_content android:layout_height=wrap_content android:layout_toRightOf=@id/find android:layout_alignTop=@id/find android:text=Cancel / /RelativeLayout The above answers your direct question but there are a few different ways to use such a layout. I know 5 techniques for setting up an AlertDialog (details are below): 1. Dialog parent class: if you need to roll a simple version. 2. AlertDialog plain (without the builder): not recommended but works. 3. AlertDialog.Builder: classic; probably better than the above 2. 4. Using the two Activity methods that are called by Android: great for persisting AlertDialog instances = better performance. 5. Using an Activity that looks like a Dialog: for fancy stuff. Details: 1. Dialog parent class: a mix of code and xml layout Dialog d = new Dialog(this); //*this* is the Activity Window w = d.getWindow((; w.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); d.setTitle(Dialog (not alert)); //your layout defined in an xml file (in res/layout) d.setContentView(R.layout.dialog_view); d.show(); 2. AlertDialog plain (not recommended but works) I sometimes use this technique in an uncaughtException method. AlertDialog error = new AlertDialog(this){ //*this* is the Activity because it needs the Context. protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); } }; error.setTitle(Anomaly Detected); error.setMessage(A possible defect has been detected in +getString(R.string.app_name) + v. +getString(R.string.versionString) +\nFor support, please write m...@myplace.com); error.show(); There are more complex versions of this technique but the other techniques below are better. 3. The AlertDialog.Builder technique: recommended, as are # 4 and 5 below. AlertDialog.Builder bookmarkDialog = new AlertDialog.Builder(this); //*this* is the Activity because it needs the Context. bookmarkDialog.setIcon(android.R.drawable.ic_menu_myplaces); bookmarkDialog.setTitle(Bookmark +getString(R.string.app_name)); AlertDialog ad = bookmarkDialog.create(); ad.requestWindowFeature(Window.FEATURE_LEFT_ICON); //more setup here... //setup completed: bookmarkDialog.show(); 4. Using Activity methods called by Android: good for persisting AlertDialog instances 4.1. you override these 2 methods: onCreateDialog(int yourId) //called by Android the first time that you call showDialog. //You may use the AlertDialog.Builder technique in this method. onPrepareDialog(int yourId, Dialog dialog) //called by Android each time the dialog is shown. //You don't create any dialog instance here; use the one given. //You can do things like dialog.setMessage(new message with new info); 4.2. and you do this somewhere in your code: showDialog(yourUniqueDialogId); 4.3. yourUniqueDialogId must be defined by you, usually as a static field; must be an int. 5. Using an Activity that looks like a Dialog: activity android:name=.ActivityDialog1 android:theme=@android:style/Theme.Dialog /activity And you manage the Activity like any another Activity. sm1 On Mar 22, 2:56 am, Lucius Fox lucius.fo...@gmail.com wrote: Hi, How is android's AlertDialog layout define? Is there a layout.xml file corresponding to the AlertDialog? I have looked at AlertDialog implementation, But i don't figure out how that is being layout (e.g. the location of the button, the location of
[android-developers] Re: How is android's AlertDialog layout define?
Thank you for both of your answers. In the android source, it has: * If you * want to display a more complex view, look up the FrameLayout called body * and add your view to it: * * pre * FrameLayout fl = (FrameLayout) findViewById(R.id.body); * fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT)); * /pre How can I hook up to that? Do I need to create a layout xml file with 'body' as it name? And how can I make an AlertDialog loads that layout xml? Thank you. On Sun, Mar 22, 2009 at 12:48 PM, sm1 sergemas...@gmail.com wrote: usually your layout is defined in an xml file (in res/layout) and in your Java-like Android code you can reference it so: d.setContentView(R.layout.dialog_view); where d is an instance of AlertDialog. and dialog_view.xml could contain: ?xml version=1.0 encoding=utf-8? RelativeLayout xmlns:android=http://schemas.android.com/apk/res/ android android:layout_width=fill_parent android:layout_height=fill_parent !-- android:title=any title does not work -- TextView android:id=@+id/label android:layout_width=fill_parent android:layout_height=wrap_content android:text=The search is case sensitive:/ EditText android:id=@+id/entry android:layout_width=fill_parent android:layout_height=wrap_content android:background=@android:drawable/editbox_background android:layout_below=@id/label/ Button android:id=@+id/find android:layout_width=wrap_content android:layout_height=wrap_content android:layout_below=@id/entry android:layout_alignParentLeft=true android:layout_marginRight=10dip android:text=Find Next / Button android:id=@+id/cancel_search android:layout_width=wrap_content android:layout_height=wrap_content android:layout_toRightOf=@id/find android:layout_alignTop=@id/find android:text=Cancel / /RelativeLayout The above answers your direct question but there are a few different ways to use such a layout. I know 5 techniques for setting up an AlertDialog (details are below): 1. Dialog parent class: if you need to roll a simple version. 2. AlertDialog plain (without the builder): not recommended but works. 3. AlertDialog.Builder: classic; probably better than the above 2. 4. Using the two Activity methods that are called by Android: great for persisting AlertDialog instances = better performance. 5. Using an Activity that looks like a Dialog: for fancy stuff. Details: 1. Dialog parent class: a mix of code and xml layout Dialog d = new Dialog(this); //*this* is the Activity Window w = d.getWindow((; w.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); d.setTitle(Dialog (not alert)); //your layout defined in an xml file (in res/layout) d.setContentView(R.layout.dialog_view); d.show(); 2. AlertDialog plain (not recommended but works) I sometimes use this technique in an uncaughtException method. AlertDialog error = new AlertDialog(this){ //*this* is the Activity because it needs the Context. protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); } }; error.setTitle(Anomaly Detected); error.setMessage(A possible defect has been detected in +getString(R.string.app_name) + v. +getString(R.string.versionString) +\nFor support, please write m...@myplace.com); error.show(); There are more complex versions of this technique but the other techniques below are better. 3. The AlertDialog.Builder technique: recommended, as are # 4 and 5 below. AlertDialog.Builder bookmarkDialog = new AlertDialog.Builder(this); //*this* is the Activity because it needs the Context. bookmarkDialog.setIcon(android.R.drawable.ic_menu_myplaces); bookmarkDialog.setTitle(Bookmark +getString(R.string.app_name)); AlertDialog ad = bookmarkDialog.create(); ad.requestWindowFeature(Window.FEATURE_LEFT_ICON); //more setup here... //setup completed: bookmarkDialog.show(); 4. Using Activity methods called by Android: good for persisting AlertDialog instances 4.1. you override these 2 methods: onCreateDialog(int yourId) //called by Android the first time that you call showDialog. //You may use the AlertDialog.Builder technique in this method. onPrepareDialog(int yourId, Dialog dialog) //called by Android each time the dialog is shown. //You don't create any dialog instance here; use the one given. //You can do things like dialog.setMessage(new message with new info); 4.2. and you do this somewhere in your code: showDialog(yourUniqueDialogId); 4.3. yourUniqueDialogId must be defined by you, usually as a static