Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. placing Item over WebView in Android
Forum Updated to NodeBB v4.3 + New Features

placing Item over WebView in Android

Scheduled Pinned Locked Moved Solved Mobile and Embedded
2 Posts 1 Posters 201 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shokarta
    wrote on last edited by
    #1

    hello,

    so we all know, that once I use WebView on Android, then its always topmost with no options to put anything over it...
    however, we must have some options...

    AI offered 3 options:

    1. use Dialog{} or Popup{} which will get topmost - it doenst
    2. Use a FrameLayout: Place your WebView inside a FrameLayout and then add the overlay view as a sibling to the WebView. This way, the overlay view can be positioned above the WebView:
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        
        <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        
        <View
            android:id="@+id/overlay"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#80000000" /> <!-- Semi-transparent overlay -->
        
    </FrameLayout>
    
    1. Custom WebView: Create a custom WebView by extending the WebView class and overriding the onDraw method to draw your overlay:
    public class CustomWebView extends WebView {
        private Paint paint = new Paint();
    
        public CustomWebView(Context context) {
            super(context);
            init();
        }
    
        public CustomWebView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        private void init() {
            paint.setColor(Color.parseColor("#80000000")); // Semi-transparent color
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRect(0, 0, getWidth(), getHeight(), paint); // Draw overlay
        }
    }
    

    do we know any other options? best just a QML so i dont need to go to Java/C++
    however if there is no other option, can I kindly ask you guys for the example step by step to make option 2 or 3 happen? I have never used Java or the XML layout, I work only with c++ and QML

    1 Reply Last reply
    1
    • S Offline
      S Offline
      shokarta
      wrote on last edited by shokarta
      #2

      at the end, only thing i figure out I can do is place an item (image/svg/etc) to the webpage via JS, something like:

      onLoadingChanged: (status) => {
      	if (!loading) {
      		const jsCode = `const img = document.createElement('img');
      			img.src = 'https_//www.google.com/image.jpg';		// note, some pages have security that wont allow images which is not from their domain... to me best oslution is not to create img here but svg which jas no link to the image, but its draw via JS
      			img.alt = 'Example Image';
      
      			img.style.position = 'fixed';	// absolute / relative, etc
      			img.style.width = '20px';
      			img.style.height = '20px';
      			img.style.top = '20px';
      			img.style.left = '20px';
      			img.style.zIndex = '999999';	// to make sure its always topmost
      
      			document.body.appendChild(img);
      
      			img.addEventListener('click', function() {
      				window.location.href = 'https://www.google.com';
      			});`;
      			webview.runJavaScript(jsCode);
      	}
      }
      
      1 Reply Last reply
      0
      • S shokarta has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved