Android:对话框在 droid 3 上有额外的、丑陋的空间?

标签 android dialog

第一张图片来自 Galaxy Note,第二张图片来自 Droid 3。它们都是由以下代码生成的。

Droid 3 上的对话框有大量额外且丑陋的空间。在更复杂的对话框中,这个空间甚至更难看。有什么办法可以预防吗?

public void onCreate(Bundle bundle)
    {
        super.onCreate(bundle);

        TextView tv = new TextView(this);
        tv.setText("Hello!");

        Dialog dialog = new Dialog(this);
        dialog.setContentView(tv);
        dialog.setTitle("Hi!");

        dialog.show();
    }

enter image description here

enter image description here

最佳答案

这些 Droid UI 自定义让我发疯!

如果您想控制对话框以使它们在不同设备上保持一致,您可以使用提供样式参数的构造函数将它们简化为基本内容。以下示例提供了一个如下所示的对话框:

sample dialog

首先,像这样实例化您的对话框(或者更好的是,创建一个扩展 Dialog 的自定义类,以便您可以重用它):

Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.custom_dialog_layout);

然后,提供一个 custom_dialog_layout.xml (可能看起来像这样):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    style="@style/VerticalLinearLayout"
    android:background="@android:color/transparent"
    android:gravity="center_vertical|center_horizontal" >

    <LinearLayout
        android:id="@+id/dialog_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="@drawable/dialog_background"
        android:orientation="vertical" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:textColor="@android:color/white"
            android:text="Hi!" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:textColor="@android:color/white"
            android:text="Hello!" />

    </LinearLayout>
</LinearLayout>

其中dialog_background.xml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners android:radius="10dp" />

    <stroke
        android:width="1dp"
        android:color="@android:color/black" />

    <gradient
        android:angle="0"
        android:startColor="@android:color/white"
        android:endColor="@android:color/white" />

</shape>

如果你真的想变得更奇特,你可以尝试使用类似这样的代码将阴影应用到dialog_layout,所以答案:https://stackoverflow.com/a/3723654/475217

关于Android:对话框在 droid 3 上有额外的、丑陋的空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9684028/

相关文章:

android - 三星齿轮配套应用深层链接

android - Android 中电子邮件的自定义标题?

android - 有没有办法在顶点着色器的一个点的位置用 fragment 着色器绘制一个圆?

asp.net-mvc-3 - mvc3 关闭对话框

blackberry - 如何关闭黑莓手机上的系统对话框?

android - 如何在特定位置显示自定义对话框?

带有淡入/淡出和加载问题的 Jquery 对话框

android - actionbar 和 tabhost/tabactivity 有什么区别

android - Delphi XE7 Android 全屏(隐藏软键)

android - 自定义对话框显示错位的内容