自定义 WebView activity页面设置为半透明

1、清单文件里面把activity 设置成 Theme.Translucent.NoTitleBar (透明),

        <activity android:name=".ui.webui.WebViewActivity"
            android:windowSoftInputMode="adjustPan|stateHidden"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:screenOrientation="portrait">
        </activity>


2、在把webView 设置成透明,在xml设置父布局为半透明:如android:background="#F5ffffff"

  webView.setBackgroundColor(0);
  webView.getBackground().mutate().setAlpha(0);
3、注意:如果你webView所在的XML布局里面 webView 与其他字控件引用的  android:background 指向同一个资源          

 如  webView 的 背景为:android:background="@color/white"

 还有一个控件A的背景也为:android:background="@color/white"

 都指向了白色 资源文件,那么 

 webView.getBackground().setAlpha(0);

方法不仅改变了 webView 的背景透明度,还修改了A控件的透明度:

默认情况下,所有的从同一资源(R.drawable.***等等)加载的实例都共享一个共用的状态,如果你更改一个实例的状态,其余的实例都会接收到相同的通知。

所以要调用:

  webView.getBackground().mutate().setAlpha(0);

参考:http://blog.csdn.net/chaozhidan/article/details/51482626




猜你喜欢

转载自blog.csdn.net/daweibalang717/article/details/79109011