Applying Styles and themes to Activity in Android

By default, an activity occupies the entire screen. However, you can also apply a dialog theme to an activity so that it is displayed as a floating dialog. For example, you might want to customize your activ- ity to display as a pop-up, warning the user about some actions that they are going to perform. In this case, displaying the activity as a dialog is a good way to get their attention.

To  apply a dialog theme to an activity, simply modify the <Activity> element in  the

AndroidManifest.xml file by adding the android:theme attribute:

<?xml version=”1.0” encoding=”utf-8”?>

<manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”net.learn2develop.Activities”

android:versionCode=”1” android:versionName=”1.0”>

<application android:icon=”@drawable/icon” android:label=”@string/app_name”>

<activity android:name=”.MainActivity” android:label=”@string/app_name” android:theme=”@android:style/Theme.Dialog”  >

<intent-filter>

<action android:name=”android.intent.action.MAIN” />

<category

android:name=”android.intent.category.LAUNCHER”  />

</intent-filter>

</activity>

</application>

<uses-sdk android:minSdkVersion=”9” />

</manifest>

Leave a Reply

Your email address will not be published. Required fields are marked *