[SOLVED] adding functionality to Webview

[SOLVED] adding functionality to Webview
0.0 0

#1

Hi I’m wondering if it is possible to make something like this I have made in obj-c:

        creditsScroll=[[UIWebView alloc] init];
        [creditsScroll setUserInteractionEnabled:true];
        [creditsScroll setBackgroundColor:[UIColor clearColor]];
        creditsScroll.opaque=NO;
        [creditsScroll setAlpha:0];
        creditsScroll.frame=CGRectMake(0, 270, 280, 370);
[[[CCDirector sharedDirector] openGLView] addSubview:creditsScroll];
        [creditsScroll loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[CCString stringWithFormat:@"INK_credits_%@",language] ofType:@"html"] isDirectory:NO]]];
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelegate:self];
        [creditsScroll setAlpha:1];
        [UIView commitAnimations];

till now I have made this:

       creditsScroll = cocos2d::experimental::ui::WebView::create();
        creditsScroll->retain();
        creditsScroll->setPosition(size * 0.5);//Vec2(0, 270));// size * 0.5);
        creditsScroll->setContentSize(size * 0.5);//(Size){280, 370});//size * 0.5);
        creditsScroll->loadFile(CCString::createWithFormat("INK_credits_%s.html",language->getCString())->getCString());
        creditsScroll->setScalesPageToFit(true);
        creditsScroll->setOpacity(0);
        this->addChild(creditsScroll);

and works but the background is white, I have not tested if I can make an animation.
How can I make the background transparent?
thanks


#2

I’m trying to add functionality to cocos2dx webview, I’d like to share implementation, I have made for iOS and Android if someone is interested

void setBackgroundColorClearJNI(const int index){
    LOGD("error: %s,%d",__func__,__LINE__);
	cocos2d::JniMethodInfo t;
	    if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setBackgroundColor", "(II)V")) {
	        t.env->CallStaticVoidMethod(t.classID, t.methodID, index, -16776961);
	        t.env->DeleteLocalRef(t.classID);
	    }
}

and

void WebViewImpl::setBackgroundColorClear(){
            	setBackgroundColorClearJNI(_viewTag);
            }

add this in Cocos2dxWebViewHelper:

public static void setBackgroundColor(final int index, final int color) {
    sCocos2dxActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Cocos2dxWebView webView = webViews.get(index);
            if (webView != null) {
                webView.setBackgroundColor(color);
            }
        }
    });
}

#4

@sefiroths, the value -16776961 is for blue color.
For transparent the color value should be 0.
Ref: https://developer.android.com/reference/android/graphics/Color.html#TRANSPARENT