Step 1: Create a background configuration file float_box.xml and put it under Res/drawable, as shown below:
<?xml version="1.0" encoding="utf-8"?><!--** Copyright 2010, Ideasandroid--><shape xmlns:android="http://schemas.android.com/apk/res/android"><solid android:color="#ffffff" /><stroke android:width="3dp" color="#000000" /><corners android:radius="3dp" /><padding android:left="10dp" android:top="10dp" android:right="10dp"android:bottom="10dp" /></shape>
Step 2: Define a dialog box style and place it in RES/values/styles. XML, as shown below:
<? XML version = "1.0" encoding = "UTF-8"?> <! -- Copyright (c) 2010 ideasandroid --> <resources> <! -- Define a style that inherits the dialog style Android: style/theme of the Android system. dieme --> <style name = "theme. floatactivity "parent =" Android: style/theme. dialog "> <! -- Float_box defines the window background for us --> <item name = "Android: windowbackground"> @ drawable/float_box </item> </style> </resources>
Step 3: Create a view configuration file Res/layout/float_activity.xml, an imageview, and a textview, as shown below:
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2010 IdeasAndroid--><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/ideasandroidlogo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:src="http://blog.163.com/dmg_123456/blog/@drawable/ideasandroid" /> <TextView android:layout_width="wrap_content" android:text="@string/ideasandroidIntr" android:layout_height="wrap_content" android:layout_below="@id/ideasandroidlogo" android:textColor="@android:color/black" /></RelativeLayout>
Step 4 create our activity as follows:
Public class floatactivitydemo extends activity {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // remove the application title bar first. Note: Before setcontentview, requestwindowfeature (window. feature_no_title); // set the window we defined as the default view setcontentview (R. layout. float_activity );}}
In the last step, change the application configuration file androidmanifest. xml and apply the style we just created to our activity, as shown below:
<activity android:name=".FloatActivityDemo" android:theme="@style/Theme.FloatActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>