3

I'm developing an Android Wear app and content on the very bottom of the screen is cropped because of the black bar.

This video says that we should get the height of the bar like this:

@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
   int barHeight = insets.getSystemWindowInsetBottom();
}

but in reality barHeight is always 0.

Right now I'm hacking it with

if (Build.MODEL.equals("Moto 360")) {

}

but that's not very future-proof. Any hints?

David Vávra
  • 18,446
  • 7
  • 48
  • 56

1 Answers1

1

I use the window insets to determine the "chin" height in an Activity of a Wear app and in a watch face engine, so it does work. I've tested on a Moto 360. This is an extract from an Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
    stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
        @Override
        public void onLayoutInflated(WatchViewStub stub) {
            stub.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                    int chinHeight = insets.getSystemWindowInsetBottom();
                    // chinHeight = 30;
                    return insets;
                }
            });
        }
    });
}
myanimal
  • 3,580
  • 26
  • 26
  • Oh I see, it seems you need to set the listener in the onLayoutInflated method, I was calling it on GridViewPager instance. – David Vávra Feb 02 '15 at 22:24