截至2016年4月,这些答案已经过时了。我现在必须这样做,所以这是我的经验。
首先,Cordova / Ionic项目被切成了插件。我们需要的是cordova-plugin-inAppBrowser回购。
步骤1
首先,我们必须在本地克隆它或在github / bitbucket上分叉。 (对于每个新项目设置,我们都需要永久克隆的repo。)我们可以使用以下命令轻松克隆repo:
git clone git@github.com:apache/cordova-plugin-inappbrowser.git第2步
然后我们必须对项目进行所请求的更改。要使Android上的网址栏行为与iOS相同,我们必须始终显示菜单栏并仅在用户请求菜单栏时显示网址栏。
控制它的代码在/src/android/InAppBrowser.java文件中。
我们必须改变707-716之间的界限。 (注意:如果修改文件,这些行号可能会改变。)
我们必须从中更改代码
// Add the views to our toolbar
toolbar.addView(actionButtonContainer);
toolbar.addView(edittext);
toolbar.addView(close);
// Don't add the toolbar if its been disabled
if (getShowLocationBar()) {
// Add our toolbar to our main view/layout
main.addView(toolbar);
}对此:
// Add the views to our toolbar
toolbar.addView(actionButtonContainer);
if (getShowLocationBar()) {
toolbar.addView(edittext);
}
toolbar.addView(close);
main.addView(toolbar);所以我们在这里做的是我们总是使用退出/前进/后退按钮添加工具栏,并且仅当用户想要完整的栏时才添加URL栏。这是iOS版本的行为。
此外,如果我们想删除前进/后退按钮,因为Android有一个本机后退按钮,那么我们必须将它们注释掉,并且只有在用户需要完整的菜单栏时才添加它们。所以我们的代码应该是这样的:
// actionButtonContainer.addView(back);
// actionButtonContainer.addView(forward);
// Add the views to our toolbar
toolbar.addView(actionButtonContainer);
if (getShowLocationBar()) {
toolbar.addView(edittext);
// We add this here if the user want the full bar, then we need this buttons.
actionButtonContainer.addView(back);
actionButtonContainer.addView(forward);
}
toolbar.addView(close);第3步
我们必须将修改后的插件添加到我们的项目中,如果您只需要一次,那么只需运行即可
cordova plugin add https://github.com/username/cordova-plugin-inappbrowser.git
// or
cordova plugin add https://UserName@bitbucket.org/UserName/cordova-plugin-inappbrowser.git代替
cordova plugin add cordova-plugin-inappbrowser注意:您必须保留修改后的repo,因为每次设置项目时,cordova plugin add命令都会从您的存储库中获取。