Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: update toolbar after rotation #1552

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mhsmith
Copy link
Member

@mhsmith mhsmith commented Aug 8, 2022

This is a follow-up to #1507.

The Android toolbar is supposed to respond to rotation in several ways:

  • In landscape mode the toolbar should be slightly narrower.
  • In landscape mode the toolbar should have a slightly smaller font size.
  • The visble commands should adapt to the available space.

None of this is currently happening, because the built-in toolbar can apparently only change these things in response to an activity restart, which we've disabled. So this PR disables the built-in toolbar and adds one of our own.

In order for this to work, these lines have to be removed from the MainActivity:

        LinearLayout layout = new LinearLayout(this);
        this.setContentView(layout);

This LinearLayout was never actually used, because Toga's set_content method simply replaced it by calling setContentView again. However, setContentView is one of the things that can trigger the creation of the built-in toolbar, and once it's created there's no way to remove it.

To move this PR out of draft status, the new toolbar needs to be fixed to have the correct theme. This is awkward because Toga doesn't know what the name of the app's R class will be. One possible solution is to look up the theme resource by name, like this.

I won't be continuing with this in the near future, so anyone else is welcome to pick it up.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@mhsmith
Copy link
Member Author

mhsmith commented Aug 8, 2022

Before
After

@mhsmith mhsmith marked this pull request as draft August 8, 2022 21:37
@mhsmith
Copy link
Member Author

mhsmith commented Aug 9, 2022

the new toolbar needs to be fixed to have the correct theme

I thought that maybe this also affected other widgets, because they show up with purple highlights:

color-toga

But it turns out this is actually the colorAccent from the theme, so that's fine.

I don't know why we need to explicitly set the theme of a Toolbar but not any other widgets. But that's what the official Toolbar example does too, although they're creating it using an XML layout file, not programmatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant