Skip to content

setClearBackgroundColor(true), 在 android 4.4.2 上无效,背景仍是白色的 #190

Open

Description

@JiangShuLiang

跪求解决办法,拜托拜托了!!!!感谢不尽!!!!
Uploading cgi-bin_mmwebwx-bin_webwxgetmsgimg_&MsgID=7898734967138859978&skey=@crypt_801aab47_6c67a647e7211bcc7e40c2d97907b279&mmweb_appid=wx_webfilehelper.jpg…

Activity

  1. JiangShuLiang commented on Feb 23, 2024

    @JiangShuLiang
    Author

    cgi-bin_mmwebwx-bin_webwxgetmsgimg_ MsgID=7898734967138859978 skey=@crypt_801aab47_6c67a647e7211bcc7e40c2d97907b279 mmweb_appid=wx_webfilehelper

  2. AAChartModel commented on Feb 23, 2024

    @AAChartModel
    Owner

    同样的代码, 在其他版本的系统上也有这个问题吗?

  3. AAChartModel commented on Feb 23, 2024

    @AAChartModel
    Owner

    看你的截图, 似乎不用设置成透明颜色, 直接设置 AAChartModel 对象的背景色和整个大屏同色, 应该也行吧?

    public class AAChartModel {
        ...
        public Object backgroundColor; //图表背景色
        ...
        public AAChart backgroundColor(Object prop) {
            backgroundColor = prop;
            return this;
        }
        ...
    }
  4. JiangShuLiang commented on Feb 29, 2024

    @JiangShuLiang
    Author

    看你的截图, 似乎不用设置成透明颜色, 直接设置 AAChartModel 对象的背景色和整个大屏同色, 应该也行吧?

    public class AAChartModel {
        ...
        public Object backgroundColor; //图表背景色
        ...
        public AAChart backgroundColor(Object prop) {
            backgroundColor = prop;
            return this;
        }
        ...
    }

    需要设成透明色的唉,因为整个背景是个地图(只是截图里没显示出来)。这个backgroundColor好像不支持透明色,我设成“#00000000”最终显示出来是白色底的

  5. JiangShuLiang commented on Feb 29, 2024

    @JiangShuLiang
    Author

    同样的代码, 在其他版本的系统上也有这个问题吗?

    不会,在模拟器,手机,电视上都安装过,都正常。唯独这个机顶盒里安装不行

  6. AAChartModel commented on Feb 29, 2024

    @AAChartModel
    Owner

    这个backgroundColor好像不支持透明色,我设成“#00000000”最终显示出来是白色底的

    AAChartView 是继承自 WebView 的, 这个 backgroundColor 设置是的绘制图表的 <div> 标签的背景色的.

  7. AAChartModel commented on Feb 29, 2024

    @AAChartModel
    Owner
        public void setIsClearBackgroundColor(Boolean isClearBackgroundColor) {
            this.isClearBackgroundColor = isClearBackgroundColor;
            if (this.isClearBackgroundColor) {
                this.setBackgroundColor(0);
                this.getBackground().setAlpha(0);
            } else {
                this.setBackgroundColor(1);
                this.getBackground().setAlpha(255);
            }
        }

    从上面的代码可以看出, setClearBackgroundColor 才是用来设置 WebView 自身为透明色的.

    所以 AAChartView 的内部实现里有这段代码

     private void configureChartOptionsAndDrawChart(AAOptions chartOptions) {
            if (isClearBackgroundColor) {
                chartOptions.chart.backgroundColor("rgba(0,0,0,0)"); //这里就是为了避免开发者忘了设置 `<div>` 的透明度
            }
    
            Gson gson = new Gson();
            String aaOptionsJsonStr = gson.toJson(chartOptions);
            this.optionsJson = aaOptionsJsonStr;
            String javaScriptStr = "loadTheHighChartView('"
                    + aaOptionsJsonStr + "','"
                    + this.contentWidth + "','"
                    + this.contentHeight + "')";
            this.safeEvaluateJavaScriptString(javaScriptStr);
        }

    其中

            if (isClearBackgroundColor) {
                chartOptions.chart.backgroundColor("rgba(0,0,0,0)"); //这里就是为了避免开发者忘了设置 `<div>` 的透明度
            }

    这段代码, 就是为了避免开发者想要 AAChartView 为透明色, 但是只设置了 setClearBackgroundColor(true) , 而忘了设置 <div> 的透明度.

    综上所述, 想要设置 AAChartView 为透明色, 需要同时保证 WebView 自身和绘制图表的 <div> 都是透明色.

  8. AAChartModel commented on Feb 29, 2024

    @AAChartModel
    Owner

    同样的代码, 在其他版本的系统上也有这个问题吗?

    不会,在模拟器,手机,电视上都安装过,都正常。唯独这个机顶盒里安装不行

    所以这个估计是这个 Android 版本系统自身的 bug, 参考:

    这里的解决方案, 在 android 4.4.2 上为 AAChartView 额外补充这段代码:

    aaChartView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

    这是为了关闭 WebView 的硬件加速功能,因为在某些情况下硬件加速会导致背景不透明.

    ⚠️注意:关闭硬件加速可能会影响性能,因此仅在必须时才禁用它(你这里应该只要确保系统版本为android 4.4.2时, 添加了这段代码即可).

  9. changed the title [-]setClearBackgroundColor(true)在android 4.4.2上无效,背景仍是白色的[/-] on Feb 29, 2024
  10. JiangShuLiang commented on Mar 4, 2024

    @JiangShuLiang
    Author

    感谢作者!这么详细的解答是我在gayhub上头一次遇到了,真心大写加粗的感谢!!!我这就去试试看!

  11. abc78998778 commented on Feb 6, 2025

    @abc78998778

    哥们解决了嘛,我也出现了同样的问题,解决了能教教嘛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions