其实在android上实现全屏效果也是很简单滴,主要用到了android为我们提供的样式,下面我贴代码了,算是自己的一个记录。

定义样式文件

在styles.xml中定义如下两个样式:

<style name="preview_dialog" parent="@android:style/Theme.Material.Light.Dialog">        <item name="android:windowTranslucentNavigation">false</item></style><style name="fullScreen_dialog" parent="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">        <item name="android:windowTranslucentNavigation">false</item></style>

显示dialog

int currentOrientation = MainActivity.this.getResources().getConfiguration().orientation;// 根据当前的屏幕是否横屏,切换当前需要用到的样式if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {    mCurrentStyle = R.style.fullScreen_dialog;} else {    mCurrentStyle = R.style.preview_dialog;}    if (null != mPreviewDialog) {        mPreviewDialog.dismiss();        mPreviewDialog = null;    }    showPreviewDialog();    mIsShowPreview = true;

showPreviewDialog

showPreviewDialog是用来显示dialog的方法。

private Dialog mPreviewDialog = null;private String mContent = "this is dialog content.....";private Drawable mAlertIcon = null;private int mCurrentStyle;private boolean mIsShowPreview = false;public void showPreviewDialog() {        mPreviewDialog = new Dialog(MainActivity.this,mCurrentStyle);        mPreviewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);        View alertReimderView = LayoutInflater.from(MainActivity.this).inflate(                R.layout.cell_broadcast_reminder, null);        ((TextView) alertReimderView.findViewById(R.id.alertTitle))            .setText(R.string.app_name);        ((ImageView) alertReimderView.findViewById(R.id.icon))            .setImageDrawable(getResources().getDrawable(R.drawable.ic_default_contact));         ((TextView) alertReimderView.findViewById(R.id.message))            .setText(mContent);         Button okBtn = (Button) alertReimderView.findViewById(R.id.dismissButton);         okBtn.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                if (null != mPreviewDialog) {                    mPreviewDialog.dismiss();                    mPreviewDialog = null;                    mIsShowPreview = false;                }            }        });         mPreviewDialog.setContentView(alertReimderView, new ViewGroup.LayoutParams(                 ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));         mPreviewDialog.setCancelable(false);         mPreviewDialog.show();}

监听切换屏幕方向

需要在当前的activity中添加如下配置:

android:configChanges="orientation|screenSize|keyboardHidden"
  • 重写onConfigurationChanged方法
@Overridepublic void onConfigurationChanged(Configuration newConfig) {        super.onConfigurationChanged(newConfig);        Log.d(TAG, "the secondactivity onconfiguration runs newConfig.orientation is :"+newConfig.orientation);        if (mIsShowPreview) {            if (newConfig.orientation==Configuration.ORIENTATION_PORTRAIT) {                if (mCurrentStyle == R.style.fullScreen_dialog) {                    mCurrentStyle = R.style.preview_dialog;                }            }              if (newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE) {                if (mCurrentStyle == R.style.preview_dialog) {                    mCurrentStyle = R.style.fullScreen_dialog;                }            }            if (null != mPreviewDialog) {                mPreviewDialog.dismiss();                mPreviewDialog = null;            }            showPreviewDialog();        }}

更多相关文章

  1. Android利用drawable文件夹自定义控件背景、样式
  2. Fragment+viewpager 傻子都能看懂的demo 实例(博主就是个傻子)
  3. Android屏幕元素层次结构
  4. Android(安卓)设定横屏,禁止屏幕旋转,Activity重置 [更新视频播放
  5. 随手记
  6. Style与Theme
  7. Android中使用Dialog风格弹出框的Activity
  8. Android学习笔记(4)——Android(安卓)Application是如何运行的
  9. 【 Android】使手机屏幕常亮,不进入待机状态

随机推荐

  1. CheckedTextView的显示问题
  2. android 环境变量搭建
  3. Android(安卓)系统广播机制
  4. android中自定义控件
  5. Android获取WIFI状态下的IP地址以及MAC地
  6. android web services
  7. Android:dimen尺寸资源文件的使用
  8. SeekBar 和 RatingBar
  9. Android2.2 API 中文文档系列(2) —— Edit
  10. 2010.11.16———android Camera 拍照的