Android Custom Activity window size (theme use)

Source: Internet
Author: User

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
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <!--
  3. * * Copyright, ideasandroid
  4. -
  5. <shape xmlns:android="http://schemas.android.com/apk/res/android">
  6. <solid android:color="#ffffff" />
  7. <stroke android:width="3DP" color="#000000" />
  8. <corners android:radius="3DP" />
  9. <padding android:left="10DP" android:top="10DP" android:right="10DP"
  10. android:bottom="10DP" />
  11. </shape>


In the second step, define a dialog box style, put it in Res/values/styles.xml, as follows:

XML code
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <!--Copyright (C) ideasandroid
  3. -
  4. <resources>
  5. <!--Define a style that inherits the dialog box style of the Android system android:style/theme.dialog-->
  6. <style name= "theme.floatactivity" parent="Android:style/theme.dialog">
  7. <!--Float_box for us to define the window background- -
  8. <item name="Android:windowbackground"> @drawable/float_box</Item >
  9. </style>
  10. </Resources>


The third step is to create a view profile Res/layout/float_activity.xml, a imageview and a TextView, as follows:

XML code
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <!--Copyright (C) ideasandroid
  3. -
  4. <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
  5. android:layout_width="fill_parent"
  6. android:layout_height="fill_parent">
  7. <ImageView
  8. android:id="@+id/ideasandroidlogo"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:layout_alignparenttop="true"
  12. android:src="@drawable/ideasandroid"
  13. />
  14. <TextView android:layout_width="wrap_content" android:text="@string/ideasandroidintr"
  15. android:layout_height="wrap_content"
  16. android:layout_below="@id/ideasandroidlogo"
  17. android:textcolor="@android: Color/black"
  18. />
  19. </relativelayout>


The fourth step is to create our activity as follows:

Java code
  1. Public class Floatactivitydemo extends Activity {
  2. @Override
  3. public void OnCreate (Bundle savedinstancestate) {
  4. super.oncreate (savedinstancestate);
  5. //Remove Application title bar First Note: Be sure to Setcontentview before
  6. Requestwindowfeature (Window.feature_no_title);
  7. //Set our defined window as the default view
  8. Setcontentview (r.layout.float_activity);
  9. }
  10. }


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
  1. <activity android:name=". Floatactivitydemo " android:theme=" @style/theme.floatactivity ">
  2. <intent-filter>
  3. <action android:name="Android.intent.action.MAIN" />
  4. <category android:name="Android.intent.category.LAUNCHER" />
  5. </intent-filter>
  6. </Activity>


Try it yourself!

Demo:http://www.ideasandroid.com/android/demo/floatactivitydemo.rar

Android Custom Activity window size (theme use)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.