標籤:idm tools int enc end shape box art idea
http://gundumw100.iteye.com/blog/906195
正常情況下,我們開發的應用程式都會上佔滿整個螢幕,那麼怎麼樣才能開發出自訂視窗大小的的程式呢?如所示:
實現起來非常簡單。
第一步,建立一個背景設定檔float_box.xml,放到res/drawable下,如下所示(如看不懂可查看本站:):
Xml代碼
- <?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>
第二步,定義一個對話方塊樣式,放到res/values/styles.xml,如下所示:
Xml代碼
- <?xml version="1.0" encoding="utf-8"?>
- <!-- Copyright (C) 2010 IdeasAndroid
- -->
- <resources>
- <!-- 定義一個樣式,繼承android系統的對話方塊樣式 android:style/Theme.Dialog-->
- <style name="Theme.FloatActivity" parent="android:style/Theme.Dialog">
- <!-- float_box為我們定義的視窗背景-->
- <item name="android:windowBackground">@drawable/float_box</item>
- </style>
- </resources>
第三步,建立一個視圖設定檔res/layout/float_activity.xml,一個ImageView和一個TextView,如下所示:
Xml代碼
- <?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="@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>
第四步建立我們的Activity,如下所示:
Java代碼
- public class FloatActivityDemo extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //先去除應用程式標題欄 注意:一定要在setContentView之前
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- //將我們定義的視窗設定為預設視圖
- setContentView(R.layout.float_activity);
-
- }
- }
最後一步,更改應用程式設定檔AndroidManifest.xml,將我們剛才建立的樣式應用到我們的Activity上,如下所示:
Xml代碼
- <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>
自己試一試吧!
Demo:http://www.ideasandroid.com/android/demo/FloatActivityDemo.rar
android自訂Activity視窗大小(theme運用)