简体   繁体   English

Chrome 自定义标签在 chrome 中作为新标签打开而不是在应用程序内,为什么?

[英]Chrome custom tab opens as a new tab in chrome not inside the app why?

How can I open my custom tab inside my app without opening Google Chrome in background...如何在不在后台打开 Google Chrome 的情况下在我的应用程序中打开我的自定义选项卡...

this is my code这是我的代码

String a="http://www.gpamravati.ac.in/gpamravati";
        CustomTabsIntent.Builder builder=new CustomTabsIntent.Builder();
        CustomTabsIntent custom=builder.build();
        custom.intent.setPackage("com.android.chrome");
        builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
        custom.launchUrl(this, Uri.parse(a));

当我单击网站菜单项时,它会调用 chrome 自定义选项卡

打开是这样的

Finally solved my problem by adding:最后通过添加解决了我的问题:

android:launchMode="singleTask"

Just add this code to your manifest under activity只需将此代码添加到活动下的清单中

Below is the output下面是输出输出

in short, you should open a fragment OnNavigationItemSelectedListener and use the webview inside the opened fragment and open the Url.简而言之,您应该打开一个片段 OnNavigationItemSelectedListener 并使用打开的片段内的 webview 并打开 Url。

xml for fragment片段的xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/container"
     android:layout_width="match_parent"
     android:layout_height="match_parent">

         <WebView
         android:id="@+id/main_webview"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />
</FrameLayout>

java code for fragment片段的java代码

    public class UrlFragment extends Fragment  {

    private WebView mWebView;

    //inflate the layout

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_url, container, false);
    return v;
   }

    @Override
    protected void onViewCreated(View view, Bundle savedInstanceState) {

        mWebView = (WebView) view(R.id.main_webview);
        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl("http://www.gpamravati.ac.in/");
        mWebView.setWebViewClient(new WebViewClient());
    }
}

and that the basic code needed to open a URL in webview inside the fragment.以及在片段内的 webview 中打开 URL 所需的基本代码。 Read morehere 在这里阅读更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么表单提交会打开新窗口/标签? - Why form submit opens new window/tab? 在Chrome中打开新标签页(不在新标签页中链接),并专注于此 - open new tab(not link in new tab) in Chrome and focus on it Selenium java 如何使用硒在 chrome 中打开一个新标签 - How to open a new tab in chrome using selenium 使用 Selenium 在 Firefox 和 Chrome 中打开新标签页不起作用 - Open new tab in Firefox and Chrome with Selenium is not working Chrome会继续在新标签页中打开pdf文件 - Chrome keeps opening the pdf file in a new tab 从RecyclerView适配器启动Chrome自定义标签 - Launching A Chrome Custom Tab from a RecyclerView Adapter chrome扩展程序-如何使用chrome扩展程序调用webDriver(不在新标签中) - chrome extension - how to invoke webDriver with chrome extension (not in a new tab) 如何直接在应用内浏览器(Chrome 自定义选项卡)中打开外部链接,而不提示浏览器 select - How to open external links directly in in-app browser (Chrome custom tab) without getting prompt to select the browser 如何在netbeans 8.2中运行chrome作为标签? - How do i run chrome as a tab inside netbeans 8.2? 无法在新标签Chrome中找到元素-使用Java的Selenium Webdriver - unable to locate element in new tab chrome - Selenium Webdriver with java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM