http://gundumw100.iteye.com/blog/906195
Under normal circumstances, we develop the application will occupy the entire screen, then how to develop a custom window size of the program? As shown in the following:
Very simple to implement.
The first step is to create a background profile float_box.xml, put it under Res/drawable, as shown below (if you can see this site:):
XML code
- <? XML version= "1.0" encoding="Utf-8"?>
- <!--
- * * Copyright, 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>
In the second step, define a dialog box style, put it in Res/values/styles.xml, as follows:
XML code
- <? XML version= "1.0" encoding="Utf-8"?>
- <!--Copyright (C) ideasandroid
- -
- <resources>
- <!--Define a style that inherits the dialog box style of the Android system android:style/theme.dialog-->
- <style name= "theme.floatactivity" parent="Android:style/theme.dialog">
- <!--Float_box for us to define the window background- -
- <item name="Android:windowbackground"> @drawable/float_box</Item >
- </style>
- </Resources>
The third step is to create a view profile Res/layout/float_activity.xml, a imageview and a TextView, as follows:
XML code
- <? XML version= "1.0" encoding="Utf-8"?>
- <!--Copyright (C) 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="@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>
The fourth step is to create our activity as follows:
Java code
- Public class Floatactivitydemo extends Activity {
- @Override
- public void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- //Remove Application title bar First Note: Be sure to Setcontentview before
- Requestwindowfeature (Window.feature_no_title);
- //Set our defined window as the default view
- Setcontentview (r.layout.float_activity);
- }
- }
As a final step, change the application configuration file Androidmanifest.xml to apply the style we just created to our activity as follows:
XML code
- <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>
Try it yourself!
Demo:http://www.ideasandroid.com/android/demo/floatactivitydemo.rar
Android Custom Activity window size (theme use)