phonegap 调用 java prompt,PhoneGap密码提示

i want to make a password prompt in phonegap.

any plugins or html/js snippet

i have tried

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

);

}

but it doesnt have any option for password

解决方案

You need to look at the native code to display password promt.

As I never need a "normal prompt", I have changed the code in the phonegap plugins for iOS and android but I am sure there is a better way to do it.

for iOS in Plugins/CDVNotification.m

- (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];

}

and for android in src/org/apache/cordova/dialogs/notification.java

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

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值