【问题标题】:How to remove white padding block from bottom of android webview app?如何从 android webview 应用程序底部删除白色填充块?
【发布时间】:2016-01-21 17:48:24
【问题描述】:

我对 android 编码很陌生,我刚刚为我的教堂创建了一个 webview 应用程序。 apk 已成功生成,但我仍然在屏幕底部看到这个烦人的空白。

到目前为止,我已经删除了 content_main.xml 文件中的所有 android:padding 引用,但仍然没有成功。

我也在这里搜索过,看看是否有其他人有同样的问题,但这些线程只帮助我摆脱了填充代码,而不是底部这个烦人的空白。

如果您需要我发布任何代码,请告诉我。提前致谢! Here is a picture of what I am talking about with the white block at bottom

activity_main.xml------------------

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimaryDark"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

activity_main.xml--------

content_main.xml-------

<ProgressBar
    android:layout_centerHorizontal="true"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal"
    android:id="@+id/progressBar1"/>

<TextView
    android:layout_below="@+id/progressBar1"
    android:layout_height="wrap_content"
    android:id="@+id/LoadingText"
    android:layout_width="fill_parent"
    android:text="Loading, Please Wait.."
    android:textSize="20sp"
    android:gravity="center_vertical|center_horizontal">
</TextView>

<WebView
    android:id="@+id/activity_main_webview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

content_main.xml--------

MainActivity.java------- 包 org.communionchapelefca.ccsatx;

    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.graphics.Bitmap;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.ProgressBar;

公共类 MainActivity 扩展 Activity {

private WebView mWebView;
ProgressBar progressBar;


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

    mWebView = (WebView) findViewById(R.id.activity_main_webview);

    progressBar = (ProgressBar) findViewById(R.id.progressBar1);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebView.loadUrl("http://communionchapelefca.org/edy-home");
    mWebView.setWebViewClient(new HelloWebViewClient());


}

private class HelloWebViewClient extends WebViewClient{


    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // TODO Auto-generated method stub
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView webView, String url)
    {
        webView.loadUrl(url);
        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);

        progressBar.setVisibility(view.GONE);
    }

}


@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{ //if back key is pressed
    if((keyCode == KeyEvent.KEYCODE_BACK)&& mWebView.canGoBack())
    {
        mWebView.goBack();
        return true;

    }

    return super.onKeyDown(keyCode, event);

}




@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

public void onBackPressed() {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            MainActivity.this);

    // set title
    alertDialogBuilder.setTitle("Exit");

    // set dialog message
    alertDialogBuilder
            .setMessage("Do you really want to exit?")
            .setCancelable(false)
            .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    // if this button is clicked, close
                    // current activity
                    MainActivity.this.finish();
                }
            })
            .setNegativeButton("No",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    // if this button is clicked, just close
                    // the dialog box and do nothing
                    dialog.cancel();
                }
            });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();
}

} MainActivity.java------------------

对于页面的 html 代码,我们使用 Wordpress 来托管它。我已经禁用了所有页脚等,因为我认为可能是罪魁祸首。打开页面 (www.communionchapelefca.org/edy-home) 时,它不会在底部显示白色块。

如果我需要发布任何其他 XML 或 java 文件,请告诉我。感谢您的帮助。

【问题讨论】:

  • 发布你的xml和相关的java代码
  • 您确定填充来自您的布局/应用程序而不是网站/HTML 本身吗?可能还需要包含您正在加载的 URL/HTML。
  • 添加了 XML 和 java 文件。关于 html 部分,我们使用 wordpress 来托管我们的网站,并且我禁用了添加页脚的页面的所有部分。您可以在此处查看链接 www.communionchapelefca.org/edy-home
  • 有人知道我做错了什么吗?

标签: android html css webview


【解决方案1】:

好吧,我为修复它所做的只是按了大约五次 enter 键(在文档中的最后一个文本之间添加空格)。然后我将文本添加到我的 html 文档的底部,然后将该文本着色为与背景相同的颜色。不是一个很好的修复,但它有效。

【讨论】:

    猜你喜欢
    • 2012-03-31
    • 2012-09-02
    • 2018-11-23
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多