Android custom activity window size

Source: Internet
Author: User

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>

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.