小编Sam*_*Sam的帖子

提交表单按钮在WebView上不起作用

在WebView中加载某些网站时,我无法提交表单.单击提交输入(按钮)时,它会聚焦,但不会发生任何其他情况.

这些相同的网站适用于Chrome(在同一设备中).

我怎样才能解决这个问题?我缺少一个设置吗?

关于这个问题发生的原因的反馈也将受到赞赏.


例

重现步骤

  1. 加载将加载的BrowseActivityhttps://m.ebay.com/
  2. 页面加载后,输入搜索查询(例如"笔记本电脑")
  3. 按表格的蓝色搜索按钮或软键盘的操作按钮(放大镜玻璃图标)

预期行为:应提交搜索表单并显示搜索结果

实际行为:蓝色搜索按钮获得焦点(由明亮的边框表示),但没有其他任何事情发生.


BrowseActivity.java

public class BrowseActivity extends AppCompatActivity {

    WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_browse);

        mWebView = (WebView) findViewById(R.id.home_wv_content);
        mWebView.setWebViewClient(new WebViewClient());
        mWebView.setWebChromeClient(new WebChromeClient());
        mWebView.getSettings().setJavaScriptEnabled(true);

        // Ebay has a blue search button where this issue can be replicated
        mWebView.loadUrl("https://m.ebay.com");
    }
}
Run Code Online (Sandbox Code Playgroud)

activity_browse.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="my.example.BrowseActivity">

    <WebView
        android:id="@+id/home_wv_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

编辑:

我考虑过使用自定义JavaScript界面来捕获按钮上的点击,阅读输入查询然后重定向到搜索页面.

无论如何,这种方法与网站本身紧密耦合(例如ebay),我希望这可以与不同的网站一起使用.此外,我不希望网站上的更改破坏我的应用程序.

android android-webview

20
推荐指数
1
解决办法
7262
查看次数

谷歌地图和协调员布局

我想模仿谷歌地图布局.看起来他们使用带有地图片段的协调器布局.问题是:

1 - 我无法设置底视图的最小值(见图1和图3).

2 - 我需要折叠的最大值,我总是希望显示地图的一部分(图2)

3 - 如果我过度折叠地图,FAB和地图会消失.

谷歌地图图片1 谷歌地图2 我的应用图片3 我的应用图片4 我的应用图片5

代码:

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <fragment
                android:id="@+id/map"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|enterAlways" />

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:clickable="true"
        android:src="@drawable/ic_photo_camera_white"
        app:backgroundTint="@color/colorPrimary"
        app:fabSize="normal"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android google-maps android-coordinatorlayout

9
推荐指数
1
解决办法
4610
查看次数

在布尔连接中分配变量时出现意外的"使用未分配的局部变量"错误

我们假设我们有这两个词典:

var dict1 = new Dictionary<string, int>();
var dict2 = new Dictionary<char, string>();
dict1.Add("foo", 42);
dict2.Add('x', "bar");

// These variables will be used for getting values from the dicts
int number;
string text;
Run Code Online (Sandbox Code Playgroud)

我们可以在text没有问题的if情况下使用它在条件中赋值(在这种情况下,via out)if:

// Example 1
if(dict1.TryGetValue("foo", out number) &&
    dict2.TryGetValue('x', out text))
{
    Console.WriteLine(text); /* Prints: bar */
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我们将条件输出到布尔变量,它将无法编译:

// Example 2
var canPrint =
    dict1.TryGetValue("foo", out number) &&
    dict2.TryGetValue('x', out text);
if(canPrint)
{
    Console.WriteLine(text); /*Use …
Run Code Online (Sandbox Code Playgroud)

c#

1
推荐指数
1
解决办法
367
查看次数