您的位置:首页 > 移动开发 > Android开发

Android Dialog控制

2015-02-19 00:00 148 查看
    一:控制Dialog 的背景方法:

      1.定义一个无背景主题主题

      <!–去掉背景Dialog–>

      <style name=”NobackDialog” parent=”@android:style/Theme.Dialog”>

      <item name=”android:windowBackground”>@color/no_back</item>

      </style>

复制代码

      2.创建Dialog

      dialog = 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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: