我不只是在API中尋找Splash Screen功能,如果可能,我希望HTML內容使用透明背景,並依靠WebView提供背景圖片。這樣的事情可能嗎?如何在Android的Cordova/PhoneGap上的WebView上設置背景圖像?
除此之外,我是否至少可以在WebView上設置背景顏色,以便「滲透」HTML內容?
我不只是在API中尋找Splash Screen功能,如果可能,我希望HTML內容使用透明背景,並依靠WebView提供背景圖片。這樣的事情可能嗎?如何在Android的Cordova/PhoneGap上的WebView上設置背景圖像?
除此之外,我是否至少可以在WebView上設置背景顏色,以便「滲透」HTML內容?
想通了在挖掘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; }
我不知道如何設置的圖像,但你可以使用此設置背景顏色:
<preference name="backgroundColor" value="0x00000000" />
您將在補充一點:RES/XML/config.xml中
Android 2.3/Cordova 2.8.1上的白色背景2.8.1 ,使用空白index.html和* {background:transparent!important; }。 –
嘗試將該代碼添加到位於/ www –
中的config.xml文件仍然沒有骰子,嘗試在2.3和4.2。 –
您可能要在構建一些自動化的這一點,但是這會工作。這就是我在啓動應用程序時在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>
在你的平臺/安卓/ manifest.xml中替換@的主題風格/ 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文件來使用。
但值得一讀的話題:http://cyrilmottier.com/2012/05/03/splash-screens-are-evil-dont-use-them/ –