cordova 不打开浏览器_如何让Cordova InAppBrowser为使用Android设备的用户提供关闭浏览器的方式?...

截至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命令都会从您的存储库中获取。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值