3

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

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

4

3 回答 3

5

在挖掘 Cordova 源代码和 Android 文档后想通了。在 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; }
于 2013-08-07T07:04:43.600 回答
1

您可能希望在构建中自动执行其中的一些操作,但这会起作用。这就是我在应用程序加载时(而不是在加载后或人为延迟后)在 Android 中出现启动画面的方式......

在platforms/android/res/values/styles.xml中创建一个文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyTheme" parent="@android:style/Theme.NoTitleBar">
        <!-- set the splash screen as the background image on all windows -->
        <item name="android:windowBackground">@drawable/screen</item>
    </style>
</resources>

在您的platforms/android/Manifest.xml 中用@style/MyTheme 替换主题

在您的 config.xml 文件中添加以下两行

<!-- make the webview transparent -->
<preference name="backgroundColor" value="0x00000000" />
<!-- cordova will copy the splash screen file to screen.png, 
     but seems to ignore it after then 
-->
<splash src="res/splash/splash.png"/>

显然,您需要使用 splash.png 文件。

于 2015-01-29T04:34:05.880 回答
1

我不确定设置图像,但您可以使用以下方法设置背景颜色:

    <preference name="backgroundColor" value="0x00000000" />

你将把它添加到:res/xml/config.xml

于 2013-08-05T22:13:10.767 回答