如何使Phonegap应用的背景透明化?

时间:2014-03-24 16:51:18

标签: android html css cordova

Phonegap用户如何让他们的应用程序背景透明,以显示设备的主屏幕?

我的html表单有一个背景图片。两者都测量460h x 320w。

当我在平板电脑上测试html(1024h x 600w)时,应用程序显示正常,但表单周围的背景颜色为黑色或白色,具体取决于我在localStorage.java文件中使用的设置。

我只希望背景颜色透明。表格和图像应保持不变。

我使用Eclipse作为我的IDE来转换我的html& css到Android应用程序。

我引用了这两个Stack Overflow帖子,但同样没有结果:

How to make the PhoneGap app's background transparent and revealing the current system wallpaper

How do I set a background image on the WebView on Cordova/PhoneGap for Android?

我也试过android:theme =" @android:style / Theme.Translucent ..",无济于事。

以下是我用过的一些注释掉的代码:

html体型:

<body style="margin:0px;font-family:Helvetica;background-image:url ('droid.png');     
background-Repeat:no-repeat;background-color:transparent !important;">

main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="320dp"
    android:layout_height="460dp"
 >
</LinearLayout>

localStorage.java:

package com.ABC.localStorage;

/* import android.app.Activity; */
import android.os.Bundle;
import org.apache.cordova.*;
import android.graphics.Color;

public class localStorage extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///android_asset/www/index.html");
        super.setIntegerProperty("backgroundColor", Color.TRANSPARENT);
        /* super.appView.setBackgroundColor(Color.TRANSPARENT); */        
       /* appView.setBackgroundColor(Color.TRANSPARENT); */
       /* appView.setBackgroundColor(Color.rgb(255,37,37)); */
       /* appView.setBackgroundColor(0x00000000); */
      /* appView.setBackgroundColor(Color.argb(125,255,37,37)); */
    }
}

的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
      package="com.ABC.localStorage" android:versionName="1.1" android:versionCode="5" android:hardwareAccelerated="true">
    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true"
        android:resizeable="true"
        android:anyDensity="true"
        />

    <uses-permission android:name="android.permission.INTERNET" />

    <application android:icon="@drawable/icon"        
        android:label="@string/app_name"
        android:theme="@style/TransparentFloatingApp"
        android:hardwareAccelerated="true"
        android:debuggable="true">
        <activity android:name="localStorage"   
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar"
                 android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17"/>
</manifest>

style.xml:

<resources>

  <style name="Theme" parent="android:Theme" />

  <style name="TransparentFloatingApp">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:background">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:backgroundDimEnabled">false</item>
      <item name="android:windowIsTranslucent">true</item>
  </style>

  <drawable name="transparent_background">#00000000</drawable>

</resources>

0 个答案:

没有答案