• Android如何创建背景透明的Dialog


    一:控制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>

    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);

  • 相关阅读:
    [算法] 带权图
    哥德巴赫猜想 ——— 极限算法(你要是能写出比我用时还短的代码算我输)
    详解 位运算
    内存对齐模式 —— 原理讲解
    C语言 文件操作
    指针与数组
    队列的实现
    堆栈的实现
    线性表 详讲及使用
    树莓派
  • 原文地址:https://www.cnblogs.com/yaowen/p/4912363.html
Copyright © 2020-2023  润新知