Monday, April 22, 2013

Howto - Create a floating dialog by theme

Create a floating dialog

As per Android doc, there're three standard ways to create a transparent/floating dialog (reference to Android doc). I tried the third one, using theme attribute to @android:style in AndroidMainfest.xml, and found it's very easy.

Herewith is the drill ...
- Create a layout xml (says select_rate.xml), just a regular layout xml.
- Create a subclass of Activity (says SelectRateActivity), just a regular Activity class, nothing special specific to the Dialog behavior. In the onCreate() method of the Activity class, use setContentView(...) to assign the layout xml as the view.
- In AndroidMainfest.xml, declare the activity as ...

<activity name=".SelectRateActivity" theme="@android:style/Theme.Dialog">