NOTE:
Use cordova.plugins.snackbar.create(text, duration, button, callback);
instead of the previous cordova.plugin.snackbar(text, duration, button, callback);
Use cordova.plugins.snackbar.close(callback);
to close the snackbar
This Update removes the need to manually modify the AndroidManifest.xml file to modify the App theme, the plugin will do that for you.
NOTE: You need to have Cordova 6.3.1 or higher to be able to do the modification automatically
Add the plugin:
cordova plugin add cordova-plugin-snackbar
phonegap plugin add cordova-plugin-snackbar
Change the Main Activity theme to AppCompact (ONLY for users that use version older than Cordova 6.3.1):
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
//Creates one snackbar at time;
cordova.plugins.snackbar.create(text, duration, button, callback);
text // String text for the Snackbar
duration //How long to show the Snackbar
parameters: "SHORT", "LONG" and "INDEFINITE" (default, show snackbar until it's dismissed by clicking the action button)
button - String text for the Action Button
callback - Callback function for the Action Button.
//Close snackbar programatically
cordova.plugins.snackbar.close(callback);
callback - Success Callback function when the snackbar closes.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
cordova.plugins.snackbar.create('This is a indefinite snackbar text', 'INDEFINITE', "Dismiss", function(){
console.log('Dismiss Button Clicked!');
});
cordova.plugins.snackbar.close(function(){
console.log('Snackbar Closed Programmatically!');
});
}