android如何设置全屏的DialogFragment以及自定义提示框支持横竖屏显示
来源:互联网 发布:网络机顶盒广告语 编辑:程序博客网 时间:2024/05/21 09:34
DialogFragment是Android3.0引入的,也是谷歌官方推荐用来创建对话框的类。
DialogFragment相对与Dialog的最大优点是在手机配置变化,导致Activity需要重新创建时,例如旋屏,基于DialogFragment的对话框将会由FragmentManager自动重建,然而基于Dialog实现的对话框则会消失。
实现标题内容的代码如下,代码中已经标注了详细的注释:
import android.app.DialogFragment;import android.content.Context;import android.content.res.Configuration;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.view.Window;import android.widget.Button;import android.widget.RelativeLayout;public class FullScreenDialogFragment extends DialogFragment {@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {//去掉dialog的标题栏getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);View view = inflater.inflate(R.layout.fragment_layout, container,false);Button btn = (Button) view.findViewById(R.id.remind_right_button);btn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {getDialog().dismiss();}});/** *通过屏幕方向来切换相应的图片 */RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.bg_layout);if (!isScreenOriatationPortrait(getActivity())) {relativeLayout.setBackgroundResource(R.drawable.remind_dialog);}return view;}@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//配置Dialog全屏setStyle(DialogFragment.STYLE_NORMAL,android.R.style.Theme_Black_NoTitleBar_Fullscreen);}/** * 判断屏幕是否是竖屏 * @param context * @return */public static boolean isScreenOriatationPortrait(Context context) {return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;}}
<?xml version="1.0" encoding="UTF-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/bg_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/remind_dialog_port" > <Button android:id="@+id/remind_right_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="30dp" android:text="确定" /></RelativeLayout>
在Activity中调用:
FullScreenDialogFragment fullScreenDialogFragment = new FullScreenDialogFragment();fullScreenDialogFragment.show(getFragmentManager(), "FullScreenDialogFragment");
0 0
- android如何设置全屏的DialogFragment以及自定义提示框支持横竖屏显示
- Android的全屏、标题栏、横竖屏设置
- 设置横竖屏切换及全屏显示
- android横竖全屏设置
- Android中两种设置全屏的方法 && Android横竖屏切换
- Android设置全屏、横竖屏的2种方法
- Android判断横竖屏以及设置横竖屏的方法
- android 设置 全屏显示 以及 设置屏幕横屏显示
- android如何设置全屏显示
- android 如何显示模态的 DialogFragment。
- 设置android的屏幕显示[横屏、竖屏/以及全屏]
- android自定义标题以及全屏设置
- Android中如何让DialogFragment全屏(DialogFragment fullscreen)
- Android中如何让DialogFragment全屏(DialogFragment fullscreen)
- Android中如何让DialogFragment全屏(DialogFragment fullscreen)
- Android如何设置横竖屏
- android 设置自定义dialog全屏显示
- 自定义dialogfragment全屏
- 启动android stdio 遇到fetching android sdk component 解决办法
- c#基础语言编程-常用函数
- FERMI-Week1
- 求字符串长度
- java缓存技术memcached实例
- android如何设置全屏的DialogFragment以及自定义提示框支持横竖屏显示
- onEnter & reloadOnSearch
- Java学习笔记(一)
- 如何正确关闭MongoDB
- Android实战技巧之十七:Linux下的模拟器硬件加速
- 启动tomcat报java.net.SocketException: select failed
- shell中双引号、单引号、反引号、反斜线
- 互联网金融“导购”的红与黑 避免比价覆辙须迈过几道坎?
- PMBOK(第五版)学习笔记 —— 2 组织影响和项目生命周期