如何在Android上的Webview中添加按钮?

3
我正在以编程方式生成一个Webview,我想在Webview上添加一个按钮。我能够添加一个普通的按钮,但是它出现在Webview之前,而不是在其上方。
有没有一种方法可以在Webview上添加按钮?

你好,你可以尝试在相对布局(父布局)中以编程方式添加一个WebView和Button。然后根据WebView的位置将Button对齐到所需的位置。 - Arpit Garg
我已经尝试过将按钮和Web视图并排或一个接一个地放置。我希望按钮位于Web视图之上。 - Rishabh
如果您发布您的XML布局文件或尝试编程添加按钮的代码行,会有人能够回答这个问题。 - Phil
2个回答

2
使用方法如下...
      <FrameLayout 
         android:layout_width="fill_parent"
         android:layout_height="500dp"
         android:layout_weight="1"
                >
            <WebView
                android:id="@+id/main_web "
                android:layout_width="fill_parent"
                android:layout_height="500dp"
                android:layout_weight="1" />

                 <ImageButton
                    android:id="@+id/refresh"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                  ></ImageButton>
        </FrameLayout>

1

您可以使用FrameLayout在WebView的顶部添加按钮。

首先将WebView添加到布局中,然后添加按钮并调整按钮的重力,使其位于所需位置。


我们在哪里可以改变重力? - Black

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接