【问题标题】:White screen partially covers my content in webview android白屏部分覆盖了我在webview android中的内容
【发布时间】:2014-07-05 23:24:50
【问题描述】:

我正在为 android 开发一个混合应用程序。 在我的代码中,我只有 webview。

当我尝试运行应用程序时,我得到一个白色矩形,它几乎覆盖了 url 的所有内容。 This is how it looks

几乎尝试了所有方法,没有成功。

这是我的“MainActivity.java”代码:

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment())
                .commit();
    }
  //  String url = "http://shop.chefnoded.co.il";
    String url = "http://myurl";
    WebView view = (WebView)this.findViewById((R.id.webView1));
    view.setWebViewClient(new WebViewClient());
    view.getSettings().setJavaScriptEnabled(true);
    view.setBackgroundColor(0x00000000);
    view.loadUrl(url);


}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        return rootView;
    }
}

}

这是activity_main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mywv.MainActivity"
tools:ignore="MergeRootFrame"

>

<WebView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/webView1"
    android:layout_gravity="center" />

如何去掉这个白色矩形? 谢谢

【问题讨论】:

    标签: android webview


    【解决方案1】:

    嗯...我用我的三星 Galaxy S4(API 级别 18)测试了代码,它运行良好,我怀疑它与设备或 API 级别有关。你有没有尝试添加

    android:hardwareAccelerated="false"

    到您在清单文件中提到的here?

    另外,您在什么设备 + API 级别上测试它?

    【讨论】:

      【解决方案2】:
          @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragment_main, container, false);
          return rootView;
      }
      

      }

      这是 google dev 自动生成的部分。工作室。 删除后,白屏消失了。

      【讨论】:

        【解决方案3】:

        如何消除 S4 上的白色矩形?

        我不确定如何对你们谈论的代码和域等进行更改。

        自从我更新了 Kit-Kat 之后,这个盒子很烦人。救命!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-03-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-26
          相关资源
          最近更新 更多