日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

android自定義Activity窗口大小(theme運用)

系統 2345 0
正常情況下,我們開發的應用程序都會上占滿整個屏幕,那么怎么樣才能開發出自定義窗口大小的的程序呢?如下圖所示:

android自定義Activity窗口大小(theme運用)

實現起來非常簡單。
第一步,創建一個背景配置文件float_box.xml,放到res/drawable下,如下所示(如看不懂可查看本站:):
    
<?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 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 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,如下所示:
    
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上,如下所示:
    
<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運用)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 修水县| 建德市| 保靖县| 将乐县| 洪洞县| 阿克苏市| 公主岭市| 泰和县| 时尚| 和田县| 郁南县| 拉萨市| 延吉市| 红原县| 济宁市| 凉城县| 松滋市| 达日县| 雷州市| 成安县| 德化县| 黔东| 永丰县| 嘉祥县| 东明县| 吕梁市| 达尔| 内江市| 沐川县| 台安县| 天台县| 剑川县| 开化县| 昌宁县| 交口县| 辽中县| 杨浦区| 湟中县| 明光市| 巩留县| 门头沟区|