怎样设置web视图的背景图像上的科尔多瓦/ PhoneGap的Andr​​oid版?视图、科尔、图像、背景

2023-09-04 05:53:54 作者:穿着校服叼着烟

我不只是寻找API中的开机画面功能;如果可能的话,我想的HTML内容使用透明背景,并依靠web视图提供背景图像。这样的事情可能吗?

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?

除了上述,我可以至少设置,将流血通过为HTML内容的WebView背景颜色?

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

推荐答案

想通挖科尔多瓦来源和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; }