本篇文章主要介绍了"将一个activity以对话框的形式悬浮在另一个activity之上",主要涉及到将一个activity以对话框的形式悬浮在另一个activity之上方面的内容,对于将一个activity以对话框的形式悬浮在另一个activity之上感兴趣的同学可以参考一下。
达到的效果就像google自带的搜索widiget中,点击录音键弹出的对话框效果一样
除了一个dialog,没有其他的东西,而且背景是半透明的。
在网上搜了一下,android自带theme如下:
•android:theme="@android:style/Theme.Dialog" 将一个Activity显示为对话框模式
•android:theme="@android:style/Theme.NoTitleBar" 不显示应用程序标题栏
•android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不显示应用程序标题栏,并全屏
•android:theme="Theme.Light" 背景为白色
•android:theme="Theme.Light.NoTitleBar" 白色背景并无标题栏
•android:theme="Theme.Light.NoTitleBar.Fullscreen" 白色背景,无标题栏,全屏
•android:theme="Theme.Black" 背景黑色
•android:theme="Theme.Black.NoTitleBar" 黑色背景并无标题栏
•android:theme="Theme.Black.NoTitleBar.Fullscreen" 黑色背景,无标题栏,全屏
•android:theme="Theme.Wallpaper" 用系统桌面为应用程序背景
•android:theme="Theme.Wallpaper.NoTitleBar" 用系统桌面为应用程序背景,且无标题栏
•android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" 用系统桌面为应用程序背景,无标题栏,全屏
•android:theme="Translucent"
•android:theme="Theme.Translucent.NoTitleBar"
•android:theme="Theme.Translucent.NoTitleBar.Fullscreen"
•android:theme="Theme.Panel"
•android:theme="Theme.Light.Panel"
其实,只要在manifest.xml文件中把<application>中设置为android:theme = "@android:style/Theme.Dialog"即可,效果如下:
在这个activity中添加去除标题栏的语句 requestWindowFeature(Window.FEATURE_NO_TITLE);
设置Activity的背景为透明色
1.先在res/valaus/下新建color.xm.文件,内容包括:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#CCCCCCCC</color> <!-- 白色 -->
<color name="darkgray">#A9A9A9</color> <!-- 暗灰色 -->
<color name="transparent">#0000</color> <!-- 透明色 -->
</resources>
2.在Activity实现中的OnCreat()方法中添加语句:
Resources res = getResources();
Drawable drawable = res.getDrawable(R.color.touming);
this.getWindow().setBackgroundDrawable(drawable);
即可。
《二》。
要让activity 的UI不显示,只是让一个activity 做某一件事情,可以设置主题为android:theme="@android:style/Theme.Translucent.NoTitleBar";
其中"@android:style/Theme.Translucent.NoTitleBar"的实现是在theme.xml文件中,进入这个theme.xml文件,<style name="Theme.Translucent.NoTitleBar">风格定义:
<style name="Theme.Translucent.NoTitleBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@null</item>
</style>
对比原来系统生成的是:
<style name="Theme.Translucent.NoTitleBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
多了最后一行:<item name="android:windowBackground">@null</item>;OK了。