標籤:android
1、首先來建立一個Activity,在Activity的OnCreate函數裡面我們設定它為全屏,然後設定Activity的寬高為全屏*0.9,然後設定背景圖片為半透明的 .9 圖片 。這樣就已經是非全屏的視窗了
this.requestWindowFeature(Window.FEATURE_NO_TITLE);this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.activity_webview);WindowManager windowManager=getWindowManager();Display display=windowManager.getDefaultDisplay();LayoutParams params=getWindow().getAttributes();params.height=(int)(display.getHeight()*0.9);params.width=(int)(display.getWidth()*0.9);params.alpha=1.0f;getWindow().setAttributes(params);getWindow().setGravity(Gravity.CENTER);getWindow().setBackgroundDrawableResource(R.drawable.webviewbg);
2、在Values/styles.xml 裡面添加一個theme 給上面建立的Activity使用。這個theme的效果是讓原來黑色的框,變為半透明
<!-- webview theme --> <style name="webviewTheme" parent="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"> <item name="android:windowFrame">@null</item><!--邊框--><item name="android:windowIsFloating">true</item><!--是否浮現在activity之上--><item name="android:windowIsTranslucent">false</item><!--半透明--><item name="android:windowNoTitle">true</item><!--無標題--><item name="android:background">@android:color/transparent</item><item name="android:windowBackground">@android:color/transparent</item><!--背景透明--><item name="android:backgroundDimEnabled">false</item><!--模糊--> </style>
3、在Manifest裡面設定Activity的theme
<activity android:name="com.crystal.geart3d.WebviewActivity" android:screenOrientation="landscape" android:theme="@style/webviewTheme" > </activity>
下面是