我想在phonegap中输入密码。 任何插件或html / js片段
我试过了
function onPrompt(results) {
alert("You selected button number " + results.buttonIndex + " and entered " + results.input1);
}
// Show a custom prompt dialog
//
function showPrompt() {
navigator.notification.prompt(
'Please enter your name', // message
onPrompt, // callback to invoke
'Registration', // title
['Ok','Exit'] // buttonLabels
);
}
但它没有任何密码选项
答案 0 :(得分:2)
您需要查看本机代码才能显示密码promt。 由于我从不需要“正常提示”,我已经更改了iOS和Android的phonegap插件中的代码,但我确信有更好的方法可以做到。
for Plugins / CDVNotification.m
中的iOS - (void)showDialogWithMessage:(NSString*)message title:(NSString*)title buttons:(NSArray*)buttons defaultText:(NSString*)defaultText callbackId:(NSString*)callbackId dialogType:(NSString*)dialogType
{
CDVAlertView* alertView = [[CDVAlertView alloc]
initWithTitle:title
message:message
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
alertView.callback
Id = callbackId;
int count = [buttons count];
for (int n = 0; n < count; n++) {
[alertView addButtonWithTitle:[buttons objectAtIndex:n]];
}
if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) {
alertView.alertViewStyle = UIAlertViewStyleSecureTextInput; /*this is what you need*/
UITextField* textField = [alertView textFieldAtIndex:0];
textField.text = defaultText;
}
[alertView show];
}
和src / org / apache / cordova / dialogs / notification.java中的android
public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels, final String defaultText, final CallbackContext callbackContext) {
final CordovaInterface cordova = this.cordova;
final EditText promptInput = new EditText(cordova.getActivity());
promptInput.setHint(defaultText);
promptInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
...
答案 1 :(得分:1)
您只需在
中添加一行App Name \ platforms \ android \ src \ org \ apache \ cordova \ dialogs \ Notification.java
promptInput.setInputType(0x00000081);