How to style Theme.Holo.DialogWhenLarge for custom size, position, margins, etc.?

I am working on my first Android application (I used to work only on iOS and WP) and tried to show activity in full-screen mode on phones and as a dialog / pop-up menu on tablets. I found Theme.Holo.DialogWhenLarge and it seems that this is what I was looking for.

Activity is displayed as a dialogue on tablets, but I did not learn how to change the size and position of the activity. It is simply displayed in the center of the screen and has the same dimensions and dimensions as on the phone. How can this be changed? Is this done directly with Activity or do I need to create a subtype?

I looked at Theme.Holo.DialogWhenLarge . This theme simply applies PreferencePanel.Dialog to preferencePanelStyle. I don’t understand how this affects the activity, which will be shown as β€œDialogue”. What is this preference panel?

How can I find out what properties of an object (view / activity) can be changed by style?

+4
source share
1 answer

I have the same problem. I have not found a way to override width and height styles in xml. The only way I found is to change the onStart window, here is the code:

@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);
}

Hope this helps!

0
source

Source: https://habr.com/ru/post/1541752/


All Articles