移动设备上的键盘输入重叠

问题描述 投票:2回答:2

我正在开发一个带有角度流星的应用程序,每当我聚焦屏幕底部的输入时,键盘就会重叠。

我尝试将其添加到我的mobile-config.js但不起作用:

App.setPreference('fullscreen', false);
App.setPreference('android-windowSoftInputMode', 'adjustResize');

还有我的index.html上的这个元数据:

<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, target-densitydpi=device-dpi, width=device-width" />

我忘记了什么吗?

android cordova meteor mobile angular-meteor
2个回答
1
投票

所以你有两个Android选项(iOS处理它对你来说更好)。在你的AndroidManifest.xml文件中,你会看到你的第一个android:windowSoftInputMode标签内的<activity>。这将调整键盘与屏幕交互的方式。 Here是关于它如何工作的更多信息。


1
投票

这几乎适用于所有情况。

此代码位于以下路径中:

── client
   ├── main.js

// Global variables 
let keyboardHeight = 0, originalHeight = 0;

Meteor.startup(() => {
    if(Meteor.isCordova){
        StatusBar.hide();

        // ionic plugin defaults to hide it
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false);

        // Android specific events
        isAndroid = cordova.platformId == 'android';
        if(isAndroid){
            // Handle android backbutton
            document.addEventListener("backbutton", onBackButtonDown, false);

            // Using ionic-plugin-keyboard
            window.addEventListener("native.keyboardshow", onShowKeyboard, false);
            window.addEventListener("native.keyboardhide", onHideKeyboard, false);
        }
    }
};
onShowKeyboard = function(e){
    let elem = document.activeElement,      // Get the focused element
        $parent = $(elem).scrollParent();   // Get closest scrollable ancestor (jQuery UI)

    // If there is no scrollable parent, no need to continue processing
    if($parent.length == 0){
        return;
    }

    // Check if the keyborad type has changed (i.e. from text to number)
    if(keyboardHeight != e.keyboardHeight){
        keyboardHeight = e.keyboardHeight;
    }

    // Don't resize if the original height hasn't been reset by onHideKeyboard()
    if(originalHeight == 0){
        originalHeight = $parent.height();
    }

    // Subtract keyboard height from parent height + accessory bar height
    // Add some class to the parent, to be able to get it back to normal state onHideKeyboard()
    $parent.height(originalHeight - keyboardHeight + 50).addClass('adjusted');

    // Give the keyboard time to show
    setTimeout(function() {     
        // Scroll to active element
        document.activeElement.scrollIntoView({
            behavior: "smooth", // or "auto" or "instant"
            block: "center"     // or "start" or "end"
        });
    }, 100);

    // Unbind DOM object from HTML for garbage collection
    elem = null;
    $parent.prevObject = null; // To avoid memory leak (for any jQuery DOM object)
    $parent = null;
};
onHideKeyboard = function(e){
    let s = $('.adjusted').attr('style');
    s = s.replace(/height.*;/, '');
    $('.adjusted').attr('style', s).removeClass('adjusted');
    keyboardHeight = 0;
    originalHeight = 0;
};
© www.soinside.com 2019 - 2024. All rights reserved.