Skip to content

Customizing your hybrid views on Android

cobaltians edited this page May 15, 2014 · 5 revisions

By default, CobaltFragment inflates a minimalist XML layout named fragment_cobalt which provides a fullscreen transparent container for your Web view.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/web_view_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent" />

You can also create your own and override the getLayoutToInflate method of your CobaltFragment to let Cobalt inflate it:

@Override
protected int getLayoutToInflate() {
    return R.layout.fragment_my;
}

If you create your own XML layout, you must define a Web view container with id web_view_container. You can also use any name and override the getWebViewContainerId method of your CobaltFragment.

@Override
protected int getWebViewContainerId() {
    return R.id.web_view_container_my;
}

Moreover, you can override setUpViews and setUpListeners methods to bind UI elements defined in your XML layout with your CobaltFragment code and add listeners to them.

Clone this wiki locally