Android jak dostosować układ w trybie pełnoekranowym, gdy widoczny jest softkeyboard

Zbadałem wiele, aby dostosować układ, gdy softkeyboard jest aktywny i z powodzeniem wdrożyłem go, ale problem pojawia się, gdy używam android:theme="@android:style/Theme.NoTitleBar.Fullscreen" tego w moim znaczniku aktywności w pliku manifestu.

Do tego użyłem android:windowSoftInputMode="adjustPan|adjustResize|stateHidden" z różnymi opcjami, ale bez powodzenia.

Potem zaimplementowałem FullScreen programowo i próbowałem różnych układów do pracy z FullScreen, ale wszystko na próżno.

Odniosłem się do tych linków i przejrzałem tutaj wiele postów związanych z tym wydanie:

Http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html

Http://davidwparker.com/2011/08/30/android-how-to-float-a-row-above-keyboard/

Oto kod xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/masterContainerView"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#ffffff">

    <ScrollView android:id="@+id/parentScrollView"
        android:layout_width="fill_parent" android:layout_height="wrap_content">

        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:orientation="vertical">

            <TextView android:id="@+id/setup_txt" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="Setup - Step 1 of 3"
                android:textColor="@color/top_header_txt_color" android:textSize="20dp"
                android:padding="8dp" android:gravity="center_horizontal" />

            <TextView android:id="@+id/txt_header" android:layout_width="fill_parent"
                android:layout_height="40dp" android:text="AutoReply:"
                android:textColor="@color/top_header_txt_color" android:textSize="14dp"
                android:textStyle="bold" android:padding="10dp"
                android:layout_below="@+id/setup_txt" />

            <EditText android:id="@+id/edit_message"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:text="Some text here." android:textSize="16dp"
                android:textColor="@color/setting_editmsg_color" android:padding="10dp"
                android:minLines="5" android:maxLines="6" android:layout_below="@+id/txt_header"
                android:gravity="top" android:scrollbars="vertical"
                android:maxLength="132" />

            <ImageView android:id="@+id/image_bottom"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:layout_below="@+id/edit_message" />

        </LinearLayout>
    </ScrollView>

    <RelativeLayout android:id="@+id/scoringContainerView"
        android:layout_width="fill_parent" android:layout_height="50px"
        android:orientation="vertical" android:layout_alignParentBottom="true"
        android:background="#535254">

        <Button android:id="@+id/btn_save" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_alignParentRight="true"
            android:layout_marginTop="7dp" android:layout_marginRight="15dp"
            android:layout_below="@+id/edit_message"
            android:text = "Save" />

        <Button android:id="@+id/btn_cancel" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_marginTop="7dp"
            android:layout_marginRight="10dp" android:layout_below="@+id/edit_message"
            android:layout_toLeftOf="@+id/btn_save" android:text = "Cancel" />

    </RelativeLayout>
</RelativeLayout>

Tutaj wpisz opis obrazka

Chcę, aby dolne przyciski 2 poszły w górę, gdy softkeyboard pojawi się na zdjęciu.

Tutaj wpisz opis obrazka

Author: Vineet Shukla, 2011-09-14

23 answers

 66
Author: nmr,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-15 23:26:17

Bazując na obejściu yghm, zakodowałem wygodną klasę, która pozwala mi rozwiązać problem za pomocą jednego linera(oczywiście po dodaniu nowej klasy do mojego kodu źródłowego). Jednowierszowe to:

     AndroidBug5497Workaround.assistActivity(this);

A Klasa implementacji to:


public class AndroidBug5497Workaround {

    // For more information, see https://issuetracker.google.com/issues/36911528
    // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.

    public static void assistActivity (Activity activity) {
        new AndroidBug5497Workaround(activity);
    }

    private View mChildOfContent;
    private int usableHeightPrevious;
    private FrameLayout.LayoutParams frameLayoutParams;

    private AndroidBug5497Workaround(Activity activity) {
        FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
        mChildOfContent = content.getChildAt(0);
        mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                possiblyResizeChildOfContent();
            }
        });
        frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
    }

    private void possiblyResizeChildOfContent() {
        int usableHeightNow = computeUsableHeight();
        if (usableHeightNow != usableHeightPrevious) {
            int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
            int heightDifference = usableHeightSansKeyboard - usableHeightNow;
            if (heightDifference > (usableHeightSansKeyboard/4)) {
                // keyboard probably just became visible
                frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
            } else {
                // keyboard probably just became hidden
                frameLayoutParams.height = usableHeightSansKeyboard;
            }
            mChildOfContent.requestLayout();
            usableHeightPrevious = usableHeightNow;
        }
    }

    private int computeUsableHeight() {
        Rect r = new Rect();
        mChildOfContent.getWindowVisibleDisplayFrame(r);
        return (r.bottom - r.top);
    }
}

Mam nadzieję, że to komuś pomoże.
 222
Author: Joseph Johnson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-10 14:50:37

Ponieważ odpowiedź została już wybrana, a problem znany jako błąd, pomyślałem, że dodam "możliwe obejście".

Możesz przełączać tryb pełnoekranowy, gdy wyświetlona jest miękka klawiatura. Dzięki temu "adjustPan" działa poprawnie.

Innymi słowy, nadal używam @android: styl/motyw.Czarny.NoTitleBar.Pełnoekranowy w ramach tematu aplikacji i stateVisible / adjustResize w ramach okna aktywności tryb miękkiego wprowadzania, ale aby uzyskać je do współpracy muszę przełączyć tryb pełnoekranowy, zanim pojawi się klawiatura.

Użyj następującego kodu:

Wyłącz tryb pełnoekranowy

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

Włącz tryb pełnoekranowy

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

Uwaga-Inspiracja pochodziła z: ukrywanie tytułu w trybie pełnoekranowym

 34
Author: LEO,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 11:54:59

Próbowałem rozwiązania od Josepha Johnsona, ale podobnie jak inni wpadłem na problem luki między treścią a klawiaturą. Problem występuje, ponieważ tryb miękkiego wprowadzania jest zawsze pan podczas korzystania z trybu pełnoekranowego. Ta Panorama zakłóca rozwiązanie Josepha, gdy aktywujesz pole wejściowe, które byłoby ukryte przez miękkie wejście.

Gdy pojawi się miękkie wejście, zawartość jest najpierw przesuwana na podstawie jego pierwotnej wysokości, a następnie zmieniana według układu wymaganego przez Rozwiązanie Josepha. Zmiana rozmiaru i późniejszy układ nie cofają panoramowania, co skutkuje przerwą. Pełna kolejność zdarzeń to:

  1. Global layout listener
  2. Panning
  3. układ treści (=rzeczywista zmiana rozmiaru treści)

Nie można wyłączyć panoramowania, ale można wymusić przesunięcie panoramowania na 0 poprzez zmianę wysokości zawartości. Można to zrobić w słuchaczu, ponieważ jest uruchamiany przed wykonaniem panoramowania. Ustawianie wysokość zawartości do dostępnej wysokości powoduje płynne działanie użytkownika, tzn. brak migotania.

Ja również dokonałem tych zmian. Jeśli któryś z tych problemów wprowadzi, daj mi znać:
  • przełączone określenie dostępnej wysokości do użycia getWindowVisibleDisplayFrame. Rect jest buforowany, aby zapobiec niepotrzebnym śmieciom.
  • pozwól, aby słuchacz również został usunięty. Jest to przydatne w przypadku ponownego użycia aktywności dla różnych fragmentów o różnych wymaganiach pełnoekranowych.
  • Do nie rozróżniaj klawiatury pokazanej lub ukrytej, ale zawsze Ustaw wysokość zawartości na widoczną wysokość ramki wyświetlacza.
[[3]} został przetestowany na Nexusie 5 i emulatorach z poziomami API 16-24 z rozmiarami ekranów od małych do dużych.

Kod został przeniesiony do Kotlina, ale przeniesienie moich zmian z powrotem do Javy jest proste. Daj znać, jeśli potrzebujesz pomocy:

class AndroidBug5497Workaround constructor(activity: Activity) {
    private val contentContainer = activity.findViewById(android.R.id.content) as ViewGroup
    private val rootView = contentContainer.getChildAt(0)
    private val rootViewLayout = rootView.layoutParams as FrameLayout.LayoutParams
    private val viewTreeObserver = rootView.viewTreeObserver
    private val listener = { possiblyResizeChildOfContent() }

    private val contentAreaOfWindowBounds = Rect()
    private var usableHeightPrevious = 0

    // I call this in "onResume()" of my fragment
    fun addListener() {
        viewTreeObserver.addOnGlobalLayoutListener(listener)
    }

    // I call this in "onPause()" of my fragment
    fun removeListener() {
        viewTreeObserver.removeOnGlobalLayoutListener(listener)
    }

    private fun possiblyResizeChildOfContent() {
        contentContainer.getWindowVisibleDisplayFrame(contentAreaOfWindowBounds)
        val usableHeightNow = contentAreaOfWindowBounds.height()
        if (usableHeightNow != usableHeightPrevious) {
            rootViewLayout.height = usableHeightNow
            // Change the bounds of the root view to prevent gap between keyboard and content, and top of content positioned above top screen edge.
            rootView.layout(contentAreaOfWindowBounds.left, contentAreaOfWindowBounds.top, contentAreaOfWindowBounds.right, contentAreaOfWindowBounds.bottom)
            rootView.requestLayout()

            usableHeightPrevious = usableHeightNow
        }
    }
}
 13
Author: Johan Stuyts,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 11:54:59

Też musiałem zmierzyć się z tym problemem i miałem pracę wokół której sprawdziłem na HTC one, galaxy S1, S2, S3, note I HTC sensation.

Umieść globalny detektor układu w głównym widoku układu

mRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(){
            public void onGlobalLayout() {
                checkHeightDifference();
            }
    });

I tam sprawdziłem różnicę wysokości i jeśli różnica wysokości ekranu jest większa niż jedna trzecia na wysokości ekranu to możemy założyć, że klawiatura jest otwarta. wzięłam to z tej odpowiedzi .

private void checkHeightDifference(){
    // get screen frame rectangle 
    Rect r = new Rect();
    mRootView.getWindowVisibleDisplayFrame(r);
    // get screen height
    int screenHeight = mRootView.getRootView().getHeight();
    // calculate the height difference
    int heightDifference = screenHeight - (r.bottom - r.top);

    // if height difference is different then the last height difference and
    // is bigger then a third of the screen we can assume the keyboard is open
    if (heightDifference > screenHeight/3 && heightDifference != mLastHeightDifferece) {
        // keyboard visiblevisible
        // get root view layout params
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mRootView.getLayoutParams();
        // set the root view height to screen height minus the height difference
        lp.height = screenHeight - heightDifference;
        // call request layout so the changes will take affect
        .requestLayout();
        // save the height difference so we will run this code only when a change occurs.
        mLastHeightDifferece = heightDifference;
    } else if (heightDifference != mLastHeightDifferece) {
        // keyboard hidden
        PFLog.d("[ChatroomActivity] checkHeightDifference keyboard hidden");
        // get root view layout params and reset all the changes we have made when the keyboard opened.
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mRootView.getLayoutParams();
        lp.height = screenHeight;
        // call request layout so the changes will take affect
        mRootView.requestLayout();
        // save the height difference so we will run this code only when a change occurs.
        mLastHeightDifferece = heightDifference;
    }
}

To chyba nie jest kuloodporne i może na niektóre urządzenia to nie będzie działać, ale to działało dla mnie i mam nadzieję, że pomoże Ci też.

 8
Author: yghm,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:34:47

Należy pamiętać, że android:windowSoftInputMode="adjustResize" nie działa, gdy WindowManager.LayoutParams.FLAG_FULLSCREENjest ustawione dla aktywności. Masz dwie opcje.

  1. Albo wyłączyć tryb pełnoekranowy dla swojej aktywności. Aktywność nie jest zmieniana w trybie pełnoekranowym. Możesz to zrobić w xml (zmieniając motyw działania) lub w kodzie Java. Dodaj następujące linie w metodzie onCreate ().

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);   
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);`
    

Lub

  1. Użyj alternatywnego sposobu, aby osiągnąć tryb pełnoekranowy. Dodaj następujący kod w metodzie onCreate ().

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    View decorView = getWindow().getDecorView();
    // Hide the status bar.
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);`
    

Należy pamiętać, że metoda 2 działa tylko w systemie Android 4.1 i nowszych.

 8
Author: Abhinav Chauhan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-01-31 05:40:53

Zaimplementowałem rozwiązanie Josepha Johnsona i działało dobrze, zauważyłem po użyciu tego rozwiązania, że czasami szuflada w aplikacji nie zamknie się prawidłowo. Dodałem funkcjonalność, aby usunąć listener removeOnGlobalLayoutListener, gdy użytkownik zamyka fragment, w którym znajdują się EditText.

    //when the application uses full screen theme and the keyboard is shown the content not scrollable! 
//with this util it will be scrollable once again
//http://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible
public class AndroidBug5497Workaround {


    private static AndroidBug5497Workaround mInstance = null;
    private View mChildOfContent;
    private int usableHeightPrevious;
    private FrameLayout.LayoutParams frameLayoutParams;
    private ViewTreeObserver.OnGlobalLayoutListener _globalListener;

    // For more information, see https://code.google.com/p/android/issues/detail?id=5497
    // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.

    public static AndroidBug5497Workaround getInstance (Activity activity) {
        if(mInstance==null)
        {
            synchronized (AndroidBug5497Workaround.class)
            {
                mInstance = new AndroidBug5497Workaround(activity);
            }
        }
        return mInstance;
    }

    private AndroidBug5497Workaround(Activity activity) {
        FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
        mChildOfContent = content.getChildAt(0);
        frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();

        _globalListener = new ViewTreeObserver.OnGlobalLayoutListener()
        {

            @Override
            public void onGlobalLayout()
            {
                 possiblyResizeChildOfContent();
            }
        };
    }

    public void setListener()
    {
         mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(_globalListener);
    }

    public void removeListener()
    {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            mChildOfContent.getViewTreeObserver().removeOnGlobalLayoutListener(_globalListener);
        } else {
            mChildOfContent.getViewTreeObserver().removeGlobalOnLayoutListener(_globalListener);
        }
    }

    private void possiblyResizeChildOfContent() {
        int usableHeightNow = computeUsableHeight();
        if (usableHeightNow != usableHeightPrevious) {
            int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
            int heightDifference = usableHeightSansKeyboard - usableHeightNow;
            if (heightDifference > (usableHeightSansKeyboard/4)) {
                // keyboard probably just became visible
                frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
            } else {
                // keyboard probably just became hidden
                frameLayoutParams.height = usableHeightSansKeyboard;
            }
            mChildOfContent.requestLayout();
            usableHeightPrevious = usableHeightNow;
        }
    }

    private int computeUsableHeight() {
        Rect r = new Rect();
        mChildOfContent.getWindowVisibleDisplayFrame(r);
        return (r.bottom - r.top);
    } 
}

Używa klasy, w której znajdują się moje edittexty

@Override
public void onStart()
{
    super.onStart();
    AndroidBug5497Workaround.getInstance(getActivity()).setListener();
}

@Override
public void onStop()
{
    super.onStop();
    AndroidBug5497Workaround.getInstance(getActivity()).removeListener();
}
 6
Author: visionix visionix,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-16 09:39:13

Właśnie znalazłem proste i niezawodne rozwiązanie, jeśli używasz podejścia system UI ( https://developer.android.com/training/system-ui/immersive.html).

Działa w przypadku, gdy używasz View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, np. jeśli używasz CoordinatorLayout.

Nie będzie działać dla WindowManager.LayoutParams.FLAG_FULLSCREEN (ten, który możesz również ustawić w temacie za pomocą android:windowFullscreen), ale możesz osiągnąć podobny efekt za pomocą SYSTEM_UI_FLAG_LAYOUT_STABLE (który "ma ten sam efekt wizualny" zgodnie z dokumentami ) i to rozwiązanie powinno działać jeszcze raz.

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION /* If you want to hide navigation */
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE)

Przetestowałem go na moim urządzeniu z Marshmallow.

Kluczem jest to, że miękkie klawiatury są również jednym z okien systemu (takich jak pasek stanu i pasek nawigacji), więc WindowInsets wysyłane przez system zawiera dokładne i wiarygodne informacje o nim.

W przypadku użycia, takim jak w DrawerLayout, gdzie próbujemy narysować za paskiem stanu, możemy utworzyć układ, który ignoruje tylko górną wstawkę i stosuje dolną wstawkę, która odpowiada softowi klawiatura.

Oto mój zwyczaj FrameLayout:

/**
 * Implements an effect similar to {@code android:fitsSystemWindows="true"} on Lollipop or higher,
 * except ignoring the top system window inset. {@code android:fitsSystemWindows="true"} does not
 * and should not be set on this layout.
 */
public class FitsSystemWindowsExceptTopFrameLayout extends FrameLayout {

    public FitsSystemWindowsExceptTopFrameLayout(Context context) {
        super(context);
    }

    public FitsSystemWindowsExceptTopFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FitsSystemWindowsExceptTopFrameLayout(Context context, AttributeSet attrs,
                                                 int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    public FitsSystemWindowsExceptTopFrameLayout(Context context, AttributeSet attrs,
                                                 int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setPadding(insets.getSystemWindowInsetLeft(), 0, insets.getSystemWindowInsetRight(),
                    insets.getSystemWindowInsetBottom());
            return insets.replaceSystemWindowInsets(0, insets.getSystemWindowInsetTop(), 0, 0);
        } else {
            return super.onApplyWindowInsets(insets);
        }
    }
}

I używać go:

<com.example.yourapplication.FitsSystemWindowsExceptTopFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Your original layout here -->
</com.example.yourapplication.FitsSystemWindowsExceptTopFrameLayout>

Teoretycznie powinno to działać na każdym urządzeniu bez szalonej modyfikacji, znacznie lepiej niż jakikolwiek hack, który próbuje wziąć losowy 1/3 lub 1/4 o rozmiarze ekranu jako odniesienie.

(wymaga API 16+, ale używam fullscreen tylko na Lollipop+ do rysowania za paskiem stanu, więc jest to najlepsze rozwiązanie w tym przypadku.)

 6
Author: Dreaming in Code,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-19 10:16:13

Aby uruchomić go na pełnym ekranie:

Użyj wtyczki klawiatury jonowej. Pozwala to słuchać, gdy pojawi się i zniknie klawiatura.

OnDeviceReady dodaj te słuchacze zdarzeń:

// Allow Screen to Move Up when Keyboard is Present
window.addEventListener('native.keyboardshow', onKeyboardShow);
// Reset Screen after Keyboard hides
window.addEventListener('native.keyboardhide', onKeyboardHide);

Logika:

function onKeyboardShow(e) {
    // Get Focused Element
    var thisElement = $(':focus');
    // Get input size
    var i = thisElement.height();
    // Get Window Height
    var h = $(window).height()
    // Get Keyboard Height
    var kH = e.keyboardHeight
    // Get Focused Element Top Offset
    var eH = thisElement.offset().top;
    // Top of Input should still be visible (30 = Fixed Header)
    var vS = h - kH;
    i = i > vS ? (vS - 30) : i;
    // Get Difference
    var diff = (vS - eH - i);
    if (diff < 0) {
        var parent = $('.myOuter-xs.myOuter-md');
        // Add Padding
        var marginTop = parseInt(parent.css('marginTop')) + diff - 25;
        parent.css('marginTop', marginTop + 'px');
    }
}

function onKeyboardHide(e) {
  // Remove All Style Attributes from Parent Div
  $('.myOuter-xs.myOuter-md').removeAttr('style');
}

Zasadniczo, jeśli różnica jest minus, to jest to ilość pikseli, które pokrywa klawiatura Twojego wejścia. Więc jeśli dostosujesz swój parent div przez to, że powinno to przeciwdziałać.

Dodanie timeoutów do logiki mówi, że 300ms powinno również Optymalizuj wydajność (ponieważ pozwoli to na pojawienie się czasu na klawiaturze.

 5
Author: tyler_mitchell,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-11 10:40:45

Użyj tylko android:windowSoftInputMode="adjustResize|stateHidden gdy używasz AdjustPan, a następnie wyłącz właściwość zmiany rozmiaru

 4
Author: Azhar Shaikh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-20 06:35:29

Próbowałem na zajęciach Josepha Johnsona i zadziałało, ale nie spełniło moich potrzeb. Zamiast emulować android: windowSoftInputMode= "adjustResize", musiałem emulować android:windowSoftInputMode="adjustPan".

Używam tego do pełnoekranowego widoku sieci Web. Aby przesunąć widok zawartości do właściwej pozycji, muszę użyć interfejsu javascript, który zawiera szczegóły dotyczące pozycji elementu strony, który ma fokus, a tym samym odbiera wejście klawiatury. Pominąłem te szczegóły, ale pod warunkiem, że przepisałem klasę Josepha Johnsona. Będzie to bardzo solidna podstawa do wdrożenia niestandardowego pan vs. jego zmiana rozmiaru.

package some.package.name;

import some.package.name.JavaScriptObject;

import android.app.Activity;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;

//-------------------------------------------------------
// ActivityPanner Class
//
// Convenience class to handle Activity attributes bug.
// Use this class instead of windowSoftInputMode="adjustPan".
//
// To implement, call enable() and pass a reference
// to an Activity which already has its content view set.
// Example:
//      setContentView( R.layout.someview );
//      ActivityPanner.enable( this );
//-------------------------------------------------------
//
// Notes:
//
// The standard method for handling screen panning
// when the virtual keyboard appears is to set an activity
// attribute in the manifest.
// Example:
// <activity
//      ...
//      android:windowSoftInputMode="adjustPan"
//      ... >
// Unfortunately, this is ignored when using the fullscreen attribute:
//      android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
//
//-------------------------------------------------------
public class ActivityPanner {

    private View contentView_;
    private int priorVisibleHeight_;

    public static void enable( Activity activity ) {
        new ActivityPanner( activity );
    }

    private ActivityPanner( Activity activity ) {
        FrameLayout content = (FrameLayout)
            activity.findViewById( android.R.id.content );
        contentView_ = content.getChildAt( 0 );
        contentView_.getViewTreeObserver().addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
                public void onGlobalLayout() { panAsNeeded(); }
        });
    }

    private void panAsNeeded() {

        // Get current visible height
        int currentVisibleHeight = visibleHeight();

        // Determine if visible height changed
        if( currentVisibleHeight != priorVisibleHeight_ ) {

            // Determine if keyboard visiblity changed
            int screenHeight =
                contentView_.getRootView().getHeight();
            int coveredHeight =
                screenHeight - currentVisibleHeight;
            if( coveredHeight > (screenHeight/4) ) {
                // Keyboard probably just became visible

                // Get the current focus elements top & bottom
                // using a ratio to convert the values
                // to the native scale.
                float ratio = (float) screenHeight / viewPortHeight();
                int elTop = focusElementTop( ratio );
                int elBottom = focusElementBottom( ratio );

                // Determine the amount of the focus element covered
                // by the keyboard
                int elPixelsCovered = elBottom - currentVisibleHeight;

                // If any amount is covered
                if( elPixelsCovered > 0 ) {

                    // Pan by the amount of coverage
                    int panUpPixels = elPixelsCovered;

                    // Prevent panning so much the top of the element
                    // becomes hidden
                    panUpPixels = ( panUpPixels > elTop ?
                                    elTop : panUpPixels );

                    // Prevent panning more than the keyboard height
                    // (which produces an empty gap in the screen)
                    panUpPixels = ( panUpPixels > coveredHeight ?
                                    coveredHeight : panUpPixels );

                    // Pan up
                    contentView_.setY( -panUpPixels );
                }
            }
            else {
                // Keyboard probably just became hidden

                // Reset pan
                contentView_.setY( 0 );
            }

            // Save usabale height for the next comparison
            priorVisibleHeight_ = currentVisibleHeight;
        }
    }

    private int visibleHeight() {
        Rect r = new Rect();
        contentView_.getWindowVisibleDisplayFrame( r );
        return r.bottom - r.top;
    }

    // Customize this as needed...
    private int viewPortHeight() { return JavaScriptObject.viewPortHeight(); }
    private int focusElementTop( final float ratio ) {
        return (int) (ratio * JavaScriptObject.focusElementTop());
    }
    private int focusElementBottom( final float ratio ) {
        return (int) (ratio * JavaScriptObject.focusElementBottom());
    }

}
 3
Author: BuvinJ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-08-06 15:58:48

Rzeczywiście wygląd miękkiej klawiatury wydaje się nie wpływać na Activity w żaden sposób, bez względu na to, co windowSoftInputMode wybieram w trybie FullScreen.

Chociaż nie mogłem znaleźć zbyt wiele dokumentacji na temat tej właściwości, myślę, że tryb FullScreen został zaprojektowany dla aplikacji do gier, które nie wymagają dużego użycia miękkiej klawiatury. Jeśli jest to działanie, które wymaga interakcji użytkownika za pomocą miękkiej klawiatury, należy rozważyć użycie motywu innego niż pełnoekranowy. Możesz wyłączyć pasek tytułu używając NoTitleBar temat. Dlaczego chcesz ukryć pasek powiadomień?

 2
Author: Arnab Chakraborty,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-26 04:50:25

Zachowaj jako android:windowSoftInputMode="adjustResize". Ponieważ podano, aby zachować tylko jeden z "adjustResize" i "adjustPan" (tryb dopasowania okna jest określony za pomocą adjustResize lub adjustPan. Zaleca się, aby zawsze podać jeden lub drugi). Znajdziesz go tutaj: http://developer.android.com/resources/articles/on-screen-inputs.html

Dla mnie działa idealnie.
 2
Author: Balaji Khadake,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-08-24 02:43:32

Dodaj android:fitsSystemWindows="true" do układu, a ten układ zmieni rozmiar.

 2
Author: zayn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-10-20 05:25:32

Chcesz, aby dolny pasek przyklejał się do dołu widoku, ale kiedy klawiatura jest wyświetlana, powinny one przesunąć się w górę, aby być umieszczone nad klawiaturą, prawda?

Możesz wypróbować ten fragment kodu:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    ...>

    <RelativeLayout
        android:id="@+id/RelativeLayoutTopBar"
    ...>
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/LinearLayoutBottomBar"
        android:layout_alignParentBottom = true
        ...>
    </LinearLayout>

    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="390dp"
    android:orientation="vertical" 
    android:layout_above="@+id/LinearLayoutBottomBar"
    android:layout_below="@+id/RelativeLayoutTopBar"> 

    <ScrollView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:id="@+id/ScrollViewBackground">

            ...

        </ScrollView>
     </LinearLayout>
  </RelativeLayout>

Pasek Dolny zostanie przyklejony do dołu widoku, a LinearLayout zawierający widok przewijania zajmie to, co pozostało z widoku po wyświetleniu górnego / dolnego paska i klawiatury. Daj mi znać, czy to działa również dla Ciebie.

 0
Author: banzai86,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-20 09:39:45

Dziękuję Józefie za odpowiedź. Jednak w metodzie possiblyResizeChildOfContent (), część

else {
            // keyboard probably just became hidden
            frameLayoutParams.height = usableHeightSansKeyboard;
        }

Nie działało dla mnie, ponieważ dolna część widoku stała się ukryta. Musiałem więc wziąć globalną zmienną restoreHeight i w konstruktorze wstawiłem ostatnią linię

restoreHeight = frameLayoutParams.height;

I wtedy wymieniłem pierwszą wspomnianą część na

else {
            // keyboard probably just became hidden
            frameLayoutParams.height = restoreHeight;
        }
Ale nie mam pojęcia, dlaczego twój kod nie zadziałał na mnie. Byłoby bardzo pomocne, gdyby ktoś mógł rzucić światło na to.
 0
Author: Debanjan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-27 09:09:55

Używałem tylko trybu pełnoekranowego, aby ukryć pasek stanu. Chcę jednak, aby aplikacja zmieniła rozmiar, gdy pojawi się klawiatura. Wszystkie inne rozwiązania (prawdopodobnie ze względu na wiek posta) były skomplikowane lub niemożliwe do użycia (chcę uniknąć zmiany kodu Javy dla sack of PhoneGap Build).

Zamiast używać pełnoekranowego, zmodyfikowałem moją konfigurację dla Androida, aby nie była pełnoekranowa:
            <preference name="fullscreen" value="false" />

I dodano cordova-plugin-statusbar, za pomocą wiersza poleceń:

cordova plugin add cordova-plugin-statusbar

Kiedy aplikacja się załaduje, po prostu wywołuję metoda na pluginie, aby się ukryć, jak:

    if (window.cordova && window.cordova.platformId == 'android' && window.StatusBar)
        window.StatusBar.hide();
To działa jak urok. Jedynym prawdziwym minusem jest to, że pasek stanu jest widoczny breifly podczas ładowania aplikacji. Jak na moje potrzeby, to nie był problem.
 0
Author: raider33,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-25 19:14:42

Wypróbowałem wszystkie możliwe odpowiedzi ze stackOverflow, w końcu rozwiązałem po tygodniu długich poszukiwań . Użyłem układu współrzędnych i zmieniłem to z linearLayout i mój problem jest naprawiony. Nie wiem, może układ współrzędnych ma błędy lub coś, co mój błąd.

 0
Author: yubaraj poudel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-26 15:23:18

W moim przypadku, ten problem zaczął się dzieje po dodaniu Crosswalk do mojej aplikacji Cordova. Moja aplikacja nie jest używana na pełnym ekranie i Androidzie: windowSoftInputMode= "adjustPan".

Miałem już wtyczkę Ionic keyboard w aplikacji, więc wykrywanie czy klawiatura była w górę czy w dół było łatwe dzięki niej:

// Listen for events to when the keyboard is opened and closed
window.addEventListener("native.keyboardshow", keyboardUp, false);
window.addEventListener('native.keyboardhide', keyboardDown, false);

function keyboardUp()
{
    $('html').addClass('keyboardUp');
}

function keyboardDown()
{
    $('html').removeClass('keyboardUp');
}

Próbowałem wszystkich poprawek powyżej, ale prosta linia, która skończyła się robi to dla mnie był ten kawałek css:

&.keyboardUp {
        overflow-y: scroll;
}

Mam nadzieję, że to uratuje ci kilka dni, które spędziłem na to. :)

 0
Author: J R,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-07-06 22:17:56

Użyłem Joseph Johnson stworzył klasę AndroidBug5497Workaround, ale uzyskując czarną przestrzeń między softkeyboard a widokiem. Odwołałem się do tego linku Greg Ennis . Po dokonaniu kilku zmian do powyższego jest to mój ostateczny kod roboczy.

 public class SignUpActivity extends Activity {

 private RelativeLayout rlRootView; // this is my root layout
 private View rootView;
 private ViewGroup contentContainer;
 private ViewTreeObserver viewTreeObserver;
 private ViewTreeObserver.OnGlobalLayoutListener listener;
 private Rect contentAreaOfWindowBounds = new Rect();
 private FrameLayout.LayoutParams rootViewLayout;
 private int usableHeightPrevious = 0;

 private View mDecorView;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_sign_up);
  mDecorView = getWindow().getDecorView();
  contentContainer =
   (ViewGroup) this.findViewById(android.R.id.content);

  listener = new OnGlobalLayoutListener() {
   @Override
   public void onGlobalLayout() {
    possiblyResizeChildOfContent();
   }
  };

  rootView = contentContainer.getChildAt(0);
  rootViewLayout = (FrameLayout.LayoutParams)
  rootView.getLayoutParams();

  rlRootView = (RelativeLayout) findViewById(R.id.rlRootView);


  rlRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
   @Override
   public void onGlobalLayout() {
    int heightDiff = rlRootView.getRootView().getHeight() - rlRootView.getHeight();
    if (heightDiff > Util.dpToPx(SignUpActivity.this, 200)) {
     // if more than 200 dp, it's probably a keyboard...
     //  Logger.info("Soft Key Board ", "Key board is open");

    } else {
     Logger.info("Soft Key Board ", "Key board is CLOSED");

     hideSystemUI();
    }
   }
  });
 }

 // This snippet hides the system bars.
 protected void hideSystemUI() {
  // Set the IMMERSIVE flag.
  // Set the content to appear under the system bars so that the 
  content
  // doesn't resize when the system bars hide and show.
  mDecorView.setSystemUiVisibility(
   View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
 }
 @Override
 protected void onPause() {
  super.onPause();
  if (viewTreeObserver.isAlive()) {
   viewTreeObserver.removeOnGlobalLayoutListener(listener);
  }
 }

 @Override
 protected void onResume() {
  super.onResume();
  if (viewTreeObserver == null || !viewTreeObserver.isAlive()) {
   viewTreeObserver = rootView.getViewTreeObserver();
  }
  viewTreeObserver.addOnGlobalLayoutListener(listener);
 }

 @Override
 protected void onDestroy() {
  super.onDestroy();
  rootView = null;
  contentContainer = null;
  viewTreeObserver = null;
 }
 private void possiblyResizeChildOfContent() {
  contentContainer.getWindowVisibleDisplayFrame(contentAreaOfWindowBounds);

  int usableHeightNow = contentAreaOfWindowBounds.height();

  if (usableHeightNow != usableHeightPrevious) {
   rootViewLayout.height = usableHeightNow;
   rootView.layout(contentAreaOfWindowBounds.left,
    contentAreaOfWindowBounds.top, contentAreaOfWindowBounds.right, contentAreaOfWindowBounds.bottom);
   rootView.requestLayout();

   usableHeightPrevious = usableHeightNow;
  } else {

   this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
  }
 }
}
 0
Author: Venkat,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-29 12:02:51

Próbowałem wielu rozwiązań, w tym Josepha Johnsona i Johana Stuytsa. ale w rezultacie dostałem białą przestrzeń między treścią a klawiaturą na niektórych urządzeniach (takich jak Lenovo S820) we wszystkich przypadkach. Więc wprowadziłem kilka zmian w ich kodach i w końcu dostałem działające rozwiązanie.

Mój pomysł polegał na dodaniu marginesu do górnej części treści podczas wyświetlania klawiatury.

contentContainer.getWindowVisibleDisplayFrame(contentAreaOfWindowBounds);
    int usableHeightNow = contentAreaOfWindowBounds.height();

    if (usableHeightNow != usableHeightPrevious) {

        int difference = usableHeightNow - usableHeightPrevious;

        if (difference < 0 && difference < -150) {
            keyboardShowed = true;
            rootViewLayout.topMargin -= difference + 30;
            rootViewLayout.bottomMargin += 30;
        }
        else if (difference < 0 && difference > -150){
            rootViewLayout.topMargin -= difference + 30;
        }
        else if (difference > 0 && difference > 150) {
            keyboardShowed = false;
            rootViewLayout.topMargin = 0;
            rootViewLayout.bottomMargin = 0;
        }

        rootView.requestLayout();

        Log.e("Bug Workaround", "Difference: " + difference);

        usableHeightPrevious = usableHeightNow;
}

Jak widać, dodaję 30 px do różnicy, ponieważ jest mała biała przestrzeń między górną częścią ekranu a strefą zawartości z margines. I nie wiem, skąd to się wydaje, więc postanowiłem po prostu zmniejszyć marginesy i teraz działa dokładnie tak, jak potrzebowałem.

 0
Author: IDmikael,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-06 11:27:27

Obecnie używam tego podejścia i działa jak urok. Sztuczka polega na tym, że otrzymujemy wysokość klawiatury z różnych metod na 21 powyżej i poniżej, a następnie używamy jej jako dolnej wyściółki naszego widoku głównego w naszej aktywności. Założyłem, że twój układ nie potrzebuje górnej wyściółki (idzie poniżej paska stanu), ale w przypadku, gdy tak, Poinformuj mnie, aby zaktualizować moją odpowiedź.

Główna aktywność.java

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        RelativeLayout mainLayout = findViewById(R.id.main_layout);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ViewCompat.setOnApplyWindowInsetsListener(mainLayout , new OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    v.setPadding(0, 0, 0, insets.getSystemWindowInsetBottom());
                    return insets;
                }
            });
        } else {
            View decorView = getWindow().getDecorView();
            final View contentView = mainLayout;
            decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    Rect r = new Rect();
                    //r will be populated with the coordinates of your view that area still visible.
                    decorView.getWindowVisibleDisplayFrame(r);

                    //get screen height and calculate the difference with the useable area from the r
                    int height = decorView.getContext().getResources().getDisplayMetrics().heightPixels;
                    int diff = height - r.bottom;

                    //if it could be a keyboard add the padding to the view
                    if (diff != 0) {
                        // if the use-able screen height differs from the total screen height we assume that it shows a keyboard now
                        //check if the padding is 0 (if yes set the padding for the keyboard)
                        if (contentView.getPaddingBottom() != diff) {
                            //set the padding of the contentView for the keyboard
                            contentView.setPadding(0, 0, 0, diff);
                        }
                    } else {
                        //check if the padding is != 0 (if yes reset the padding)
                        if (contentView.getPaddingBottom() != 0) {
                            //reset the padding of the contentView
                            contentView.setPadding(0, 0, 0, 0);
                        }
                    }
                }
            });
        }
    }
...
}

Nie zapomnij zaadresować widoku głównego za pomocą id:

Activity_main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
Mam nadzieję, że to komuś pomoże.
 0
Author: Sdghasemi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-10-03 08:31:34

Na podstawie https://stackoverflow.com/a/19494006/1815624 i pragnienie, aby to się stało...

Updated idea


Łączenie odpowiedzi z

Odpowiedni kod:

        if (heightDifference > (usableHeightSansKeyboard / 4)) {

            // keyboard probably just became visible
            frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        } else {

            // keyboard probably just became hidden
            if(usableHeightPrevious != 0) {
                frameLayoutParams.height = usableHeightSansKeyboard;
                activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
                activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

            }

Pełne źródło na https://github.com/CrandellWS/AndroidBug5497Workaround/blob/master/AndroidBug5497Workaround.java

Stary pomysł

Utwórz statyczną wartość wysokości kontenerów przed otwarciem klawiatury Ustawia wysokość kontenera na podstawie usableHeightSansKeyboard - heightDifference, gdy klawiatura się otworzy i ustaw ją z powrotem na zapisaną wartość, gdy się zamknie

if (heightDifference > (usableHeightSansKeyboard / 4)) {
                // keyboard probably just became visible
                frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
                int mStatusHeight = getStatusBarHeight();
                frameLayoutParams.topMargin = mStatusHeight;
                ((MainActivity)activity).setMyMainHeight(usableHeightSansKeyboard - heightDifference);

                if(BuildConfig.DEBUG){
                    Log.v("aBug5497", "keyboard probably just became visible");
                }
            } else {
                // keyboard probably just became hidden
                if(usableHeightPrevious != 0) {
                    frameLayoutParams.height = usableHeightSansKeyboard;
                    ((MainActivity)activity).setMyMainHeight();    
                }
                frameLayoutParams.topMargin = 0;

                if(BuildConfig.DEBUG){
                    Log.v("aBug5497", "keyboard probably just became hidden");
                }
            }

Metody w MainActivity

public void setMyMainHeight(final int myMainHeight) {

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ConstraintLayout.LayoutParams rLparams =  (ConstraintLayout.LayoutParams) myContainer.getLayoutParams();
            rLparams.height = myMainHeight;

            myContainer.setLayoutParams(rLparams);
        }

    });

}

int mainHeight = 0;
public void setMyMainHeight() {

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ConstraintLayout.LayoutParams rLparams =  (ConstraintLayout.LayoutParams) myContainer.getLayoutParams();
            rLparams.height = mainHeight;

            myContainer.setLayoutParams(rLparams);
        }

    });

}

Przykładowy kontener XML

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
        <android.support.constraint.ConstraintLayout
            android:id="@+id/my_container"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintHeight_percent=".8">

Podobnie marginesy mogą być dodawane w razie potrzeby...

Inny rozważa się użycie padding przykład tego można znaleźć pod adresem:

Https://github.com/mikepenz/MaterialDrawer/issues/95#issuecomment-80519589

 0
Author: CrandellWS,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-10-05 14:45:15