Android如何建立背景透明的Dialog

來源:互聯網
上載者:User

標籤:

一:控制Dialog 的背景方法:1.定義一個無背景主題主題<!--去掉背景Dialog--><style name="NobackDialog" parent="@android:style/Theme.Dialog"><item name="android:windowBackground">@color/no_back</item></style>2.建立Dialogdialog = new Dialog(this,R.style.dialog);dialog.setContentView(R.layout.dialog_loading);or:dialog = new Dialog(this,R.style.NobackDialog);LayoutInflater mInflater = LayoutInflater.from(this);View dialogProcessBar = mInflater.inflate(R.layout.dialog_loading,null);dialog.setView(dialogProcessBar,0, 0, 0, 0);二:控制Dialog 以及內部控制項的背景方法:dialog = new Dialog(this,R.style.dialog);WindowManager.LayoutParams lp=dialog.getWindow().getAttributes();// 模糊度getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); dialog.getWindow().setAttributes(lp);lp.alpha=0.5f;(0.0-1.0)//透明度,黑暗度為lp.dimAmount=1.0f;三:去掉邊框、title 等參數<resources><style name="dialog" parent="@android:style/Theme.Dialog"><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/black</item><item name="android:windowBackground">@null</item><item name="android:backgroundDimEnabled">false</item><!--模糊--></style></resources>
android Dialog去掉標題列 和邊框

首先在 values/Style.xml檔案中加入以下代碼(如果沒有該檔案就建立一個XML名為Style.xml)

<!--重寫系統彈出Dialog -->    <style name="myDialogTheme" parent="android:Theme.Dialog">        <item name="android:windowFrame">@null</item>        <item name="android:windowIsFloating">true</item>        <item name="android:windowIsTranslucent">false</item>         <item name="android:windowNoTitle">true</item><!--除去title-->        <item name="android:windowContentOverlay">@null</item>         <item name="android:backgroundDimEnabled">false</item>        <item name="android:windowBackground">@null</item><!--除去背景色-->
</style>

去掉背景色邊框也就去掉了,在你的層中設定背景色就可以了  

第二步在AndroidManifest.xml中在你註冊activity中加入android:theme="@style/myDialogTheme" 這個名就是上面的樣式名稱

<activity android:name=".LoginDialog" android:theme="@style/myDialogTheme" android:screenOrientation="portrait"/>

彈出層方法

 Intent intent=new Intent(Detail_Goods.this,LoginDialog.class);
startActivity(intent);

Android如何建立背景透明的Dialog

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.