如何在 Cordova/PhoneGap for Android 上的 WebView 上设置背景图像? [英] How do I set a background image on the WebView on Cordova/PhoneGap for Android?

查看:26
本文介绍了如何在 Cordova/PhoneGap for Android 上的 WebView 上设置背景图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不只是在 API 中寻找启动画面功能;如果可能,我希望 HTML 内容使用透明背景,并依靠 WebView 提供背景图像.这种事情可能吗?

I'm not just looking for the Splash Screen functionality in the API; if possible, I would like the HTML content to use a transparent background, and lean on the WebView to supply the background image. Is such a thing possible?

除此之外,我至少可以在 WebView 上设置一个背景颜色,它会渗透"到 HTML 内容中吗?

Barring that, can I at least set a background color on the WebView that will "bleed through" to HTML content?

推荐答案

在挖掘 Cordova 源代码和 Android 文档后弄清楚了.在 src/com/.../MyApp.java 中:

Figured it out after digging in Cordova source and Android docs. In src/com/.../MyApp.java:

public class MyApp extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        super.loadUrl(Config.getStartUrl(), 20000);

        // Must be after loadUrl!
        super.appView.setBackgroundColor(0x00000000); // transparent RGB
        super.appView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

        // Put background image in res/drawable/splash.jpg
        Drawable theSplash = getResources().getDrawable(R.drawable.splash);
        super.root.setBackground(theSplash);
    }
}

和 CSS:

html,
body,
.transparent { background-color: transparent !important; }

这篇关于如何在 Cordova/PhoneGap for Android 上的 WebView 上设置背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆