【问题标题】:Displaying a Dialog with a full screen image only takes up 80% of the screen全屏显示Dialog只占屏幕的80%
【发布时间】:2015-09-01 15:01:44
【问题描述】:

我想全屏显示图像,然后在用户按下它时关闭它。

我正在使用一个对话框,它占据了大约 80% 的屏幕。我的图像周围有一个白色边框(它不在我的文件系统中)。

如何让这个对话框全屏显示?

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        boolean viewedInstructions = sharedPreferences.getBoolean("instructions_viewed", false);
        if (!viewedInstructions) {
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putBoolean("instructions_viewed", true);
            editor.commit();

            final Dialog d = new Dialog(this);
            d.requestWindowFeature(Window.FEATURE_NO_TITLE);
            d.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            d.setContentView(R.layout.instructions_dialog);
            d.findViewById(R.id.tutorial).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    d.dismiss();
                }
            });

            d.show();

布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/dialog_layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:orientation="vertical"
    android:padding="10dp"
    >


    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/tutorial"
        android:src="@drawable/dashboard_instructions"/>

</LinearLayout>

【问题讨论】:

  • 您是否尝试使用@android:style/Theme.Translucent.NoTitleBar 作为您的对话框样式?
  • 如何更改对话框的主题?

标签: android dialog viewgroup layoutparams


【解决方案1】:

尝试改变这一行

final Dialog d = new Dialog(this);

final Dialog d = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);

【讨论】:

  • 我将其标记为接受,这很好,但屏幕仍然有白色边框,但比我的要好。
  • 您仍然可以更改对话框的背景颜色,但您必须使用这样的背景标签来填充布局:android:background="@android:color/background_dark">
【解决方案2】:

试试这个:

 final Dialog d = new Dialog(this,R.style.MyDialogStyle);

并在你的styles.xml中定义这个样式:

 <!-- Animation for dialog box -->
    <style name="MyDialogStyle"       parent="@android:style/Theme.Translucent.NoTitleBar">
    </style>

你也可以在Manifest中定义,为activity设置:

<activity
    android:name="com.example.YourActivity"
    android:theme="@android:style/Theme.Translucent.NoTitleBar">
 </activity>

【讨论】:

    猜你喜欢
    • 2017-03-19
    • 2018-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-30
    相关资源
    最近更新 更多