Android Activity 懸浮 半透明邊框

來源:互聯網
上載者:User

標籤: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>

下面是


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.