2013-06-20

Use Style definition to remove title bar when using Activity as Dialog

When using Activity as Dialog, you'll use the dialog theme in AndroidManifest.xml
For example:
<activity
    android:label="@string/app_name"
    android:name=".MyDialog"
    android:theme="@android:style/Theme.Dialog"
    android:configChanges="orientation" >
</activity>
If you want to make this dialog without title, one solution is to add
requestWindowFeature(Window.FEATURE_NO_TITLE);
into you Activity onCreate() method, just right after super.onCreate()


Today I'm gonna use another way to remove title on this activity dialog.
Add a new style definition into your styles.xml (sometimes located in res/values/)
<style name="NoTitleDialog" parent="android:style/Theme.Dialog">
    <item name="android:windowNoTitle">true</item>
</style>
And then goto your AndroidManifest.xml, change your activity dialog theme to this new style:
 <activity
    android:label="@string/app_name"
    android:name=".MyDialog"
    android:theme="@style/NoTitleDialog"
    android:configChanges="orientation" >
</activity>
Done!!

No comments: