【问题标题】:How to style Theme.Holo.DialogWhenLarge to custom size, position, margins, etc.?如何将 Theme.Holo.DialogWhenLarge 设置为自定义大小、位置、边距等?
【发布时间】:2014-07-12 16:49:51
【问题描述】:

我正在开发我的第一个 Android 应用程序(之前只在 iOS 和 WP 上工作过),并尝试在手机上全屏显示活动,并在平板电脑上显示为对话框/弹出窗口。我找到了 Theme.Holo.DialogWhenLarge ,这似乎就是我想要的。

活动在平板电脑上显示为对话框,但我不知道如何更改活动的大小和位置。它只是简单地显示在屏幕中心,并且与手机上的大小和尺寸大致相同。这怎么能改变?这是由 Activity 直接完成的还是我必须创建一个子样式?

我看过Theme.Holo.DialogWhenLarge。这个主题只是将 PreferencePanel.Dialog 应用于preferencePanelStyle。我不明白这如何影响显示为对话框的活动。这个 PreferencePanel 是什么?

一般来说,我怎样才能知道样式可以更改对象(视图/活动)的哪些属性?

【问题讨论】:

    标签: android android-layout android-activity


    【解决方案1】:

    我也有同样的问题。我没有找到任何方法来覆盖 xml 上的宽度和高度样式。 我发现的唯一方法是更改​​onStart上的窗口,这里是代码:

    @Override
    public void onStart() {
        super.onStart();
        // In order to not be too narrow, set the window size based on the screen resolution:
        final int new_window_width = 505;
        final int new_window_height = 502;
        WindowManager.LayoutParams layout = getDialog().getWindow().getAttributes();
        layout.width = new_window_width;
        layout.height = new_window_height;
        getDialog().getWindow().setAttributes(layout);
    }
    

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 2011-09-03
      • 1970-01-01
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      • 2020-03-16
      • 1970-01-01
      相关资源
      最近更新 更多