Android Activity以Dialog的方式打开

全屏样式的Activity

1、AndroidManifest.xml 文件中,申明 activity 的主题使用自定义样式:@style/share_activity_styles

<activity
     android:name="com.ecej.ehome.ui.AppointmentTimeActivity"
     android:screenOrientation="portrait"
     android:theme="@style/share_activity_styles"/>
效果图:


2、res/values/styles.xml 样式文件中定义一个对话框主题样式,这里继承了兼容包AppCompat_v7中的主题:Theme.AppCompat.   Light.DarkActionBar

<style name="share_activity_styles" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowFullscreen">true</item>
        <!--设置dialog的背景-->
        <item name="android:windowBackground">@android:color/transparent</item>
        <!--设置Dialog的windowFrame框为无-->
        <item name="android:windowFrame">@null</item>
        <!--设置无标题-->
        <item name="windowNoTitle">true</item>
        <!--是否浮现在activity之上-->
        <item name="android:windowIsFloating">true</item>
        <!--是否半透明-->
        <item name="android:windowIsTranslucent">true</item>
        <!--设置窗口内容不覆盖-->
        <item name="android:windowContentOverlay">@null</item>
        <!--设置动画,在这里使用让它继承系统的Animation.Dialog-->
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <!--背景是否模糊显示-->
        <item name="android:backgroundDimEnabled">true</item>
</style>


Dialog样式的Activity

1、AndroidManifest.xml 文件中,申明 activity 的主题使用自定义样式:@style/activity_styles

<activity android:name="com.ecej.ehome.ui.BActivity"
              android:theme="@style/activity_styles">
</activity>

效果图:


2、res/values/styles.xml 样式文件中定义一个对话框主题样式,这里继承了@android:style/Theme.Dialog

<style name="activity_styles" parent="@android:style/Theme.Dialog">
        <item name="android:windowBackground">@color/dialog_bg_color</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFrame">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">false</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:backgroundDimEnabled">false</item>
    </style>

android自带的其他样式theme如下:
<android:theme="Theme.Black"  背景黑色
<android:theme="Theme.Light"  背景白色
<android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  不显示应用程序标题栏,并全屏
<android:theme="Theme.Light.NoTitleBar"  白色背景并无标题栏
<android:theme="@android:style/Theme.Dialog"   将一个Activity显示为对话框模式
<android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen"  用系统桌面为应用程序背景,无标题栏,全屏
<android:theme="Theme.Black.NoTitleBar"  黑色背景并无标题栏
<android:theme="Theme.Black.NoTitleBar.Fullscreen"    黑色背景,无标题栏,全屏
<android:theme="Theme.Wallpaper"  用系统桌面为应用程序背景
<android:theme="@android:style/Theme.NoTitleBar"  不显示应用程序标题栏
<android:theme="Theme.Wallpaper.NoTitleBar"  用系统桌面为应用程序背景,且无标题栏
<android:theme="Theme.Light.NoTitleBar.Fullscreen"  白色背景,无标题栏,全屏 

更多Theme 介绍参考:https://blog.csdn.net/wjc295/article/details/54347807



猜你喜欢

转载自blog.csdn.net/l707941510/article/details/80655737