以下是Android Studio代码,同时我添加了下面的html代码,使用JavaScript在cookie中记住用户名和密码。它只在某些Android设备上有效。我不知道为什么。我希望它能在所有Android设备上运行。 希望有一个简单的方法实现。请帮忙看看。 我希望用户只需在第一次输入用户名/密码,下次访问时就可以自动填写。
public class MainActivity extends AppCompatActivity {
private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Go To Our Facebook Page");
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.hksalonjob.comslogin.php");
}
在这里使用HTML代码,使用JavaScript来记住用户名和密码。
<!DOCTYPE HTML>
<html>
<head>
<title>Salon Job HK</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]-->
<script src="js/jquery.min.js"></script>
<script src="js/jquery.scrolly.min.js"></script>
<script src="js/jquery.dropotron.min.js"></script>
<script src="js/jquery.scrollex.min.js"></script>
<script src="js/skel.min.js"></script>
<script src="js/skel-layers.min.js"></script>
<script src="js/init.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<noscript>
<link rel="stylesheet" href="css/skel.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/style-xlarge.css" />
</noscript>
<!--[if lte IE 9]><link rel="stylesheet" href="css/ie/v9.css" /><![endif]-->
<!--[if lte IE 8]><link rel="stylesheet" href="css/ie/v8.css" /><![endif]-->
</head>
<body>
<!-- Header -->
<!-- Main -->
<div id="main" class="wrapper style1">
<div class="container">
<form ACTION="<?php echo $loginFormAction; ?>" name="form1" method="POST">
<div class="12u$">
<input type="tel" name="tel" required id="tel" pattern="[0-9]{1}[0-9]{7}" maxlength="8" value="" placeholder="phone number"/>
</div>
<br>
<div class="12u$">
<input type="password" name="spassword" required id="spassword" maxlength="8" placeholder="" />
</div>
<br>
<div class="12u$">
<input type="checkbox" name="sremember" id="sremember" />
<label for="sremember">Remember me</label>
</div>
<INPUT Type="submit" class="button special fit" name="Login" id="Login" value="login">
</form>
<script>
//remember username and password
$(function() {
if (localStorage.chkbx && localStorage.chkbx != '') {
$('#sremember').attr('checked', 'checked');
$('#tel').val(localStorage.tel);
$('#spassword').val(localStorage.spassword);
} else {
$('#sremember').removeAttr('checked');
$('#tel').val('');
$('#spassword').val('');
}
$('#sremember').click(function() {
if ($('#sremember').is(':checked')) {
// save username and password
localStorage.tel = $('#tel').val();
localStorage.spassword = $('#spassword').val();
localStorage.chkbx = $('#sremember').val();
} else {
localStorage.tel = '';
localStorage.spassword = '';
localStorage.chkbx = '';
}
});
});
</script>
</div>
</div>
</body>
</html>