Android使用Dialog风格弹出框的Activity_安卓软件开发教程-查字典教程网
Android使用Dialog风格弹出框的Activity
Android使用Dialog风格弹出框的Activity
发布时间:2016-12-28 来源:查字典编辑
摘要:在Android中经常会遇到需要使用Dialog风格弹出框的activity,首先我们可能会首先想到的是在XML布局文件中设置android...

在Android中经常会遇到需要使用Dialog风格弹出框的activity,首先我们可能会首先想到的是在XML布局文件中设置android:layout_height="wrap_content"属性,让activity的高度自适应,显然这还不行,我们还需要为其DialogActivity设置自定义一个样式

<style name="dialogstyle"> <> <item name="android:windowBackground">@android:color/transparent</item> <> <item name="android:windowFrame">@null</item> <> <item name="android:windowNoTitle">true</item> <> <item name="android:windowIsFloating">true</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">true</item> </style>

然后在AndroidManifest.xml中设置DialogActivity的样式为我们自定义的dialogstyle

如下是布局的代码

<"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>

接下来我们再看一下效果图是不是我们想要的呢

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持查字典教程网。

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新安卓软件开发学习
    热门安卓软件开发学习
    编程开发子分类