Phonegap android add windowSoftInputMode using config.xml - android

I am creating a phonegap application and for android build I want to set the windowSoftInputMode property of Andriod manifest file using config.xml.
Is there any way to do it using config.xml or command line.Kindly suggest.
Thanks in advance.

Add following preference in your config.xml file :
<preference name="android-windowSoftInputMode" value="stateVisible|adjustResize" />
Also you have to disable the full-screen preference :
<preference name="Fullscreen" value="false" />
Check more :
Android+PhoneGap: android:windowSoftInputMode doesn't seem to work
Cordova Bug

Related

How to avoid overwriting AndroidManifest.xml in Cordova Android application?

I am creating an application using Cordova. In the platforms folder there is an AndroidManifest.xml file where we can specify the version and other things. But whenever I run the app using cordova run android it reinitializes the file and makes it to the previous state as it was before editing and specifying version name.
Does anyone knows how to stop replacing that file while running that command?
Try specifying the sdk versions in your config.xml, as it is the source for generating the AndroidManifest. Your can add the sdk versions in your config.xml like this:
<preference name="android-maxSdkVersion" value="23" />
<preference name="android-minSdkVersion" value="19" />
<preference name="android-targetSdkVersion" value="20" />

config.xml vs AndroidManifest.xml?

In Cordova/Android, what's the difference between:
/appname/config.xml
/appname/platforms/android/AndroidManifest.xml
Which one do I edit, or do I edit them both?
I'm looking to do things such as:
force portrait mode (I found this setting in config.xml)
specify minimum sdk supported for android. (I found this setting in AndroidManifest.xml)
You support to modify at /appname/config.xml
When you add a platform, ionic will regenerate /appname/platforms/android/AndroidManifest.xml file for you to build android app. So, it will collect the permission from your plugin and config.xml to build AndroidManifest.xml
Only update config.xml (not AndroidManifest.xml as it gets generated whenever you do a build)
For example to do portait add in config.xml:
<preference name="orientation" value="portrait" />
And to set minimum sdk add in config.xml:
<platform name="android">
<preference name="android-minSdkVersion" value="19" />
</platform>

Cordova + Android - android-windowSoftInputMode adjustPan not working

I'm using Cordova 5.4.0 and I have this in my config.xml:
<preference name="fullscreen" value="false" />
<preference name="android-windowSoftInputMode" value="adjustPan" />
but after building, in my AndroidManifest.xml there still is
android:windowSoftInputMode="adjustResize"
Why is it not working? And how can I solve it?
The android-windowSoftInputMode preference seems to be supported by Phonegap only, not Cordova.
Workaround 1 (Cordova 6.4+): use edit-config
Make sure the xmlns:android="http://schemas.android.com/apk/res/android" namespace attribute is included in the widget element and add an edit-config element:
<widget xmlns:android="http://schemas.android.com/apk/res/android" ...>
...
<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[#android:name='MainActivity']" mode="merge">
<activity android:windowSoftInputMode="adjustPan" />
</edit-config>
...
</widget>
Workaround 2 (prior to Cordova 6.4): use a plugin
Add the cordova-custom-config plugin:
cordova plugin add cordova-custom-config
Add the following preference:
<platform name="android">
<preference name="android-manifest/application/activity/#android:windowSoftInputMode" value="adjustPan" />
...
</platform>
Workaround 3: add a before_build hook
Add the following hook to config.xml:
<hook type="before_build" src="scripts/appBeforeBuild.js" />
Add a file appBeforeBuild.js to the scripts directory with the following content:
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var pathToManifest = path.join(__dirname, '../platforms/android', 'AndroidManifest.xml');
if(fs.existsSync(pathToManifest)) {
var config = fs.readFileSync(pathToManifest, 'utf8');
var result = config.replace(/(android:windowSoftInputMode=").*?(")/, '$1adjustPan$2');
fs.writeFileSync(pathToManifest, result, 'utf8');
console.log('Set android:windowSoftInputMode to adjustPan');
}
else {
console.log('Could not find AndroidManifest to set android:windowSoftInputMode');
}
This script will use Node to lookup the AndroidManifest and do a regex replace on the android:windowSoftInputMode attribute (first occurrence only).
I found a simple solution using the edit-config tag which is built into cordova since v6.4.0. My config.xml now looks like this and the keyboard no longer resizes the viewport!
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>HelloWorld</name>
<!-- ... -->
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/activity[#android:name='MainActivity']">
<activity android:name="MainActivity" android:windowSoftInputMode="adjustPan" />
</edit-config>
<!-- ... -->
</widget>
Hint: When experimenting to get this working, I made some accidental changes to my AndroidManifest.xml. You can reset this easily be removing and re-adding the android platform to your cordova project like so: cordova platform rm android && cordova platform add android.
Try this one
Index.html
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width, height=device-height">
config.xml
<preference name="android-windowSoftInputMode" value="adjustResize|adjustPan" />
It looks like you are changing the wrong AndroidManifest.xml.
In your application, under \platform\android... you will find the .xml file, you have to change that one.
You can also use the cordova-custom-config
cordova plugin add cordova-custom-config
and add this to your config.xml
<platform name="android">
<preference name="android-manifest/application/activity/#android:windowSoftInputMode" value="adjustPan" />
</platform>
I had the same problem and it turned out to be a problem with using display: flex for the container of the inputs. Changing the CSS so the container was not flexbox based solved the keyboard / input / scroll interaction problem on Android for me.

Cordova Splashscreen does not work with Intel XDK

I activated the splashscreen plugin, created 9patch files and inserted them into the assets. What is more, I added this..
<preference name="SplashScreenDelay" value="10000" />
<preference name="SplashMaintainAspectRatio" value="true" />
to my intelxdk.config.additions.xml file and use
navigator.splashscreen.hide();
in my onDeviceReady event.
The splashscreen does not show anyway, when I build the app with Crosswalk.
What am I doing wrong? It would be nice, if you could help me with that.
Thx in advance.

splash screen is not showing on android

i have really searched about the problem but didn't find the correct solution that's why again here..
i have a Ionic+ Cordova project i want to show Splash Screen on android. project include a
res folder and inside that a drawable folder where i have placed my screen.png which i want to show.
but the problem is the file is not showing .
what is the problem how to show
i have include below line of code in config.xml which is inside of root folder
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="20000" />
<preference name="auto-hide-splash-screen" value="false" />
and my splash screen is here
platforms/android/res/drawable/screen.png
before app load a black than white backgound shows..
You need to install the splashscreen plugin in order to use it.
You can write the preferences in the config.xml, but I would recommand to do use the platform tag. Also make sure that you provide a splashscreen for each resolution in the drawables folder
<platform name="android">
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="1500" />
</platform>
Did you add the SplashScreen to AndroidManifest.xml ?

Categories

Resources