WebView 와 CustomTab

 

Vue.JS로 개발된 프론트를 WebView로 노출하려고 했는데 페이지가 안뜨고 에러가 발생한다. 

 

그래서 Custom Tab으로 만들어보라고 해서 해봤다.

 

생각보다 간단한 코드인데 정확한 방법이 잘 검색이 안나왔다.

 

build.gradle(Module: 앱이름.app) 에 dependencies를 추가한다. 버전은 맨 아래 링크를 참조했으면 한다.

dependencies {
    ...
    implementation "androidx.browser:browser:1.3.0"
}

 

소스는 기본적으로 4줄이면 끝이다.

MainActivity.java

String url = "https://google.com/";
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));

 

여기서 색상이라던지 작업 버튼을 구성을 하고 싶으면 바로 아래 링크를 확인하면 된다.

 

https://developer.chrome.com/docs/android/custom-tabs/integration-guide/#configure-the-color-of-the-address-bar

 

Implementation guide - Chrome Developers

Custom Tabs implementation guide

developer.chrome.com

https://developer.chrome.com/docs/android/custom-tabs/

 

Overview - Chrome Developers

An overview of Custom Tabs

developer.chrome.com

 

+ Recent posts