今天要做Dialog,由于某些功能的實作,需要用到applicationContext,是以決定使用Activity來做。方法是在在配置檔案AndroidManifest.xml上加上一個主題:
XML/HTML代碼
<activity android:name=".NumberInputActivity" android:theme="@android:style/Theme.Panel"></activity>
這個主題是從螢幕底部彈出的,類似彈出輸入法的效果。還有
<style name="Theme.Dialog">
這是在螢幕中間彈出Dialog,其他效果可以參考themes.xml配置檔案,有詳細的解釋。
然後設定位置或者背景可以使用如下的方法:
Java代碼
WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay(); //為擷取螢幕寬、高
LayoutParams p = getWindow().getAttributes(); //擷取對話框目前的參數值
p.height = (int) (d.getHeight() * 1.0); //高度設定為螢幕的1.0
p.width = (int) (d.getWidth() * 0.7); //寬度設定為螢幕的0.8
p.alpha = 1.0f; //設定本身透明度
p.dimAmount = 0.0f; //設定黑暗度
getWindow().setAttributes(p); //設定生效
本文轉自06peng 51CTO部落格,原文連結:http://blog.51cto.com/06peng/963241,如需轉載請自行聯系原作者