The Android dialogs that we have used so far all have a similar appearance to them which may not match the specific look of our activities. Fortunately we can create customized dialogs in XML and maintain a consistent feel to our applications.
Once a custom dialog has been defined it can be summoned in exactly the same way as any other dialog, so either start up a new project or load any of those we have used in this chapter thus far.
We define our customized dialog box with an XML layout. Begin by creating a new Android XML file in the
res/layout
folder, alongsidemain.xml
calledmy_custom_dialog.xml
or some such name.We only need one view to demonstrate how to customize a dialog box. Add the TextView below to a vertical LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="6dip...