android - 是否可以在调试期间更改 Web View 的 Assets CSS 文件?

标签 android css debugging webview

我有一个包含 WebView 的 Activity 。在 webview 的 HTML 代码中,我引用了“assets”中的 CSS 文件。

当我开始调试应用程序并进入 webview 以查看 CSS 的效果时,我想“即时”更改 CSS 文件,以在重新加载持有 webview 的 Activity 后查看我的更改.

目前我更改了 CSS,然后启动应用程序,使用 Web View 导航到 Activity 并检查它是否看起来不错。然后我返回,更改 CSS 并重新启动应用程序。这非常耗时且糟糕。

如果在调试期间更改 CSS 不起作用,请提供有关如何实现快速 CSS 编辑的任何建议。

谢谢。

最佳答案

您无法修改资源文件夹。您可以通过以下代码将文件从 asset 文件夹复制到 SD 卡:

private void CopyAssetsbrochure() {

        File direct = new File(
                android.os.Environment.getExternalStorageDirectory()
                        + File.separator + "songs");

        direct.mkdirs();

        AssetManager assetManager = this._context.getResources().getAssets();

        String[] files = null;

        try {
            files = assetManager.list("songs"); // songs is folder
                                                        // name
        } catch (Exception e) {
            Log.e("", "ERROR: " + e.toString());
        }
        for (int i = 0; i < files.length; i++) {
            InputStream in = null;
            OutputStream out = null;
            try {
                in = assetManager.open("songs" + File.separator
                        + files[i]);
                out = new FileOutputStream(
                        android.os.Environment.getExternalStorageDirectory()
                                + File.separator + "songs"
                                + File.separator + files[i]);

                byte[] buffer = new byte[65536 * 2];
                int read;
                while ((read = in.read(buffer)) != -1) {
                    out.write(buffer, 0, read);
                }
                in.close();
                in = null;
                out.flush();
                out.close();
                out = null;
                Log.d("copy", "Ringtone File Copied in SD Card");
            } catch (Exception e) {
                Log.e("error", "ERROR: " + e.toString());
            }
        }

    }

并且不要忘记授予像这样显示的权限:

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

已编辑:

Currently I changed the CSS, and then start the app, navigate to the activity with the webview and checked if it looks good. Then I go back, change the CSS and restart the app. This is very time consuming and sucks.

由于 css 用于 webview 并且 webview 是在 Activity 下加载的,因此无法不重新启动应用程序。因为没有像浏览器那样的刷新(F5)方法可以使您的页面刷新以加载您所做的所有更改。

关于android - 是否可以在调试期间更改 Web View 的 Assets CSS 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20396989/

相关文章:

javascript - 如何使一个 HTML 文件中的触摸事件影响另一个 HTML 文件中的事物?

javascript - 在不使用 JQuery 的情况下更改滚动位置的 div 样式

html - 无论页面高度如何,在浏览器底部设置页脚

c - 在 Mavericks (OS X 10.9) 上开发 PostgreSQL

android - 启动 Activity 时出错

android - Android Phonegap 上的应用程序错误

android - 如何将动画添加到 Activity 完成()

android - 我们可以提高 android 视频 View 的音量吗?

java - 要设置哪些 Java 命令行选项以允许远程调试 JVM?

javascript - React 子组件渲染错误