Attila Orosz Attila Orosz - 6 months ago 118
Android Question

Android: Resize EditText when Appcomat bottomsheet shows

I have a multiline EditText and a button, The button brings up a persistent bottom sheet (modal would not do here).

The bottomsheet is basically a LinearLayout, turned into an appcompat bottomsheet, with

app:layout_behavior="@string/bottom_sheet_behavior"


in the XML.

The the buttonpress brings it up like this:

View bottomSheet = context.findViewById(R.id._bottom_sheet);

BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);

behavior.setState(BottomSheetBehavior.STATE_EXPANDED);


Now, I know it's expected behaviour, that the bottom sheet covers whatever is there (and I do not want to make it modal, for the EditText needs to retain its focus and selection, etc.), but my question is:

Is there a way to make the bottom view resize the EditText, so that is always show "whole"? Something like when you show a keyboard.

(Edited: the original question would allow for panning, which would hide the top portion of the view)

Or am I better off just turning it into a "regular" view, and make it "come up" with button click?

Thanks for your insight.

Edit: I also need to mention, the Bottomsheet is defined on the main activity, while the EditText is on a ViewPager in a fragment (which makes resizing less than straightforward)

Answer

Turns out the problem was not really a problem, but a wrong approach towards solving something. The EditText in question was itself placed on a ViewPager. Resizing the Viewpager itself resized everything in it, and correctly resizing the EditText.

Thanks to m vai's comment above to direct me to this solution.