在AndroID中经常会遇到需要使用Dialog风格d出框的activity,首先我们可能会首先想到的是在XML布局文件中设置androID:layout_height="wrap_content"属性,让activity的高度自适应,显然这还不行,我们还需要为其DialogActivity设置自定义一个样式
<style name="dialogstyle"> <!--设置dialog的背景--> <item name="androID:windowBackground">@androID:color/transparent</item> <!--设置Dialog的windowFrame框为无--> <item name="androID:windowFrame">@null</item> <!--设置无标题--> <item name="androID: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>
然后在AndroIDManifest.xml中设置DialogActivity的样式为我们自定义的dialogstyle
如下是布局的代码
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:background="@color/white" androID:orIEntation="vertical"> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="65dp" androID:orIEntation="horizontal" androID:paddingleft="@dimen/acitvity_margin" androID:paddingRight="@dimen/acitvity_margin"> <linearLayout androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:layout_weight="1" androID:orIEntation="horizontal"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:gravity="center" androID:text="上班时间:" androID:textcolor="@color/grey" androID:textSize="@dimen/size_text_medium" /> <button androID:ID="@+ID/tv_signin_time" androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:background="@color/white" androID:gravity="center" androID:text="9:00" androID:textcolor="@color/grey" androID:textSize="@dimen/size_text_medium" /> </linearLayout> <linearLayout androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:layout_weight="1" androID:orIEntation="horizontal"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:gravity="center" androID:text="下班时间:" androID:textcolor="@color/grey" androID:textSize="@dimen/size_text_medium" /> <button androID:ID="@+ID/tv_signout_time" androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:background="@color/white" androID:gravity="center" androID:text="18:00" androID:textcolor="@color/grey" androID:textSize="@dimen/size_text_medium" /> </linearLayout> </linearLayout> <relativeLayout androID:layout_wIDth="match_parent" androID:layout_height="65dp" androID:paddingleft="@dimen/acitvity_margin" androID:paddingRight="@dimen/acitvity_margin"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:layout_alignParentleft="true" androID:gravity="center" androID:text="公司位置:" androID:textcolor="@color/grey" androID:textSize="@dimen/size_text_medium" /> <EditText androID:ID="@+ID/et_address" androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:layout_marginleft="2dp" androID:layout_toRightOf="@+ID/tv_address" androID:background="@color/white" androID:hint="请输入公司位置" androID:singleline="true" androID:textSize="@dimen/size_text_small" /> <TextVIEw androID:ID="@+ID/tv_location" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParentRight="true" androID:layout_centerInParent="true" androID:gravity="center" androID:padding="5dp" androID:text="重新定位" androID:textcolor="@color/blue" androID:textSize="@dimen/size_text_medium" /> </relativeLayout> <relativeLayout androID:layout_wIDth="match_parent" androID:layout_height="65dp" androID:paddingleft="@dimen/acitvity_margin" androID:paddingRight="@dimen/acitvity_margin"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:layout_alignParentleft="true" androID:gravity="center" androID:text="设置管理员:" androID:textcolor="@color/grey" androID:textSize="@dimen/size_text_medium" /> <ImageVIEw androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:layout_alignParentRight="true" androID:gravity="center" androID:src="@mipmap/icon_toright" /> </relativeLayout></linearLayout>
接下来我们再看一下效果图是不是我们想要的呢
源码下载:http://xiazai.jb51.net/201609/yuanma/DialogActivity(jb51.net).rar
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。
总结以上是内存溢出为你收集整理的Android使用Dialog风格d出框的Activity全部内容,希望文章能够帮你解决Android使用Dialog风格d出框的Activity所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)