2

I have a custom view and want to apply adjustResize logic to it, something like we can do with soft keyboard.

 android:windowSoftInputMode="adjustResize"

My custom view extends LinearLayout. Is it possible to allow the window to be resized when this custom view is shown, so that its contents are not covered by the view?

Any help will be appreciated.

Andrey Mohyla
  • 218
  • 7
  • 17

1 Answers1

0

I haven't tried this, but here is one possibility:

Let's say you add a custom attribute to your custom view. Let's call it "imeVisible".

layout/view.xml:

    ...
    app:imeVisible="false"
    ...

layout-keysexposed/view.xml:

   ...
   app:imeVisible="true"
   ...

I am assuming the system will generate a configuration change for IME show/hide when you have something in layout-keysexposed, because normally it doesn't.

But it will do a layout change (adjustResize), so another more generic approach would be to just override onLayout() in your custom view:

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {

        super.onLayout(changed, l, t, r, b);

        int height = b - t;
        // logic here for different heights
    }
kris larson
  • 30,387
  • 5
  • 62
  • 74
  • @LalitJadav It was just an example of a custom attribute for a view. See https://stackoverflow.com/q/3441396/4504191 – kris larson Aug 01 '18 at 15:06
  • Looking it over, I think I probably misunderstood the question. It seems like the OP either wanted A) a custom input method editor, which is a totally separate topic, or B) a way to update the layout when a hidden view was shown. I guess describing the `onLayout` override gave the OP what was needed. – kris larson Aug 01 '18 at 15:11
  • can you help to use imeVisible attribute. I have defined it but not know how to use it – Lalit Jadav Aug 02 '18 at 04:20