2017-04-14 104 views
1

我正在开发一个角流星应用程序,每次我将焦点放在屏幕底部的一个输入上,键盘与它重叠。移动键盘上的输入重叠

我尝试添加这对我的移动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" /> 

我是不是忘了什么东西?

+0

你达到了一个解决方案?我有相同的设置,并渴望使它工作! – Roshdy

+0

找不到任何东西,sz –

+0

我做了一个工作hacky的解决方法,如果你有兴趣,让我知道这里发布 – Roshdy

回答

0

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

+0

所以我理解它应该是adjustPan,而不是adjustResize(不知道为什么人们会推荐这个)。无论如何我都试过,也不管用。 在流星我已经在我的应用程序根移动config.js。这是我应该改变的。在.meteor/local/cordova-build上我找到了config.xml(由第一个参数生成)。在最后一个platform/android/AndroidManifest.xml中生成一个,但是我找不到最后一个在第一个参数上添加的这个参数 –

+0

我也尝试将这个属性直接添加到AndroidManifest。 xml(我知道我不应该编辑这个,这只是一个尝试),但该应用程序不编译 –

+0

@DanielRodriguez我对Meteor不太熟悉 - 是的,你应该直接将这个属性添加到AndroidManifest.xml文件,尽管我不知道Meteor如何处理这个问题 –

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; 
};