您的位置:首页 > 其它

设置theme实现类似于自定义dialog效果

2016-06-14 16:49 423 查看
我们知道我们要实现自定义dialog可以自己自定义,那么还有一种方法就是让activity变成窗体,那么我们在设置Theme就可以了

我们来看效果



点击后弹出一个类似气泡的东西

Android平台定义的主题样式:

android:theme=”@android:style/Theme.Dialog” 将一个Activity显示为对话框模式

•android:theme=”@android:style/Theme.NoTitleBar” 不显示应用程序标题栏

•android:theme=”@android:style/Theme.NoTitleBar.Fullscreen” 不显示应用程序标题栏,并全屏

•android:theme=”@android:style/Theme.Light” 背景为白色

•android:theme=”@android:style/Theme.Light.NoTitleBar” 白色背景并无标题栏

•android:theme=”@android:style/Theme.Light.NoTitleBar.Fullscreen” 白色背景,无标题栏,全屏

•android:theme=”@android:style/Theme.Black” 背景黑色

•android:theme=”@android:style/Theme.Black.NoTitleBar” 黑色背景并无标题栏

•android:theme=”@android:style/Theme.Black.NoTitleBar.Fullscreen” 黑色背景,无标题栏,全屏

•android:theme=”@android:style/Theme.Wallpaper” 用系统桌面为应用程序背景

•android:theme=”@android:style/Theme.Wallpaper.NoTitleBar” 用系统桌面为应用程序背景,且无标题栏

•android:theme=”@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen” 用系统桌面为应用程序背景,无标题栏,全屏

•android:theme=”@android:style/Translucent” 半透明效果

•android:theme=”@android:style/Theme.Translucent.NoTitleBar” 半透明并无标题栏

•android:theme=”@android:style/Theme.Translucent.NoTitleBar.Fullscreen” 半透明效果,无标题栏,全屏

•android:theme=”@android:style/Theme.Panel”

我们来看看代码

新建一个activity 在manifest声明 然后设置Theme为自己写的style 我的叫”DialogStyle” 继承于@android:style/Theme.Dialog

设置属性

<style name="DialogStyle" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
//设置背景为透明
<item name="android:windowNoTitle">true</item>
//  设置无标题
<item name="android:backgroundDimEnabled">true</item>
//  此属性可以翻译为 是否允许对话框的背景变暗?如果允许背景就变暗了。
</style>


弹出的activity的xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/bubble"
android:text="@string/hello_world" />

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="94dp"
android:layout_marginLeft="26dp"
android:orientation="vertical" >
</LinearLayout>

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/linearLayout1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="183dp"
android:text="我是对话框"
android:textSize="30sp" />

</RelativeLayout>


如果要实现自定义dialog也可以这样呦
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: