在WebView中加载某些网站时,我无法提交表单.单击提交输入(按钮)时,它会聚焦,但不会发生任何其他情况.
这些相同的网站适用于Chrome(在同一设备中).
我怎样才能解决这个问题?我缺少一个设置吗?
关于这个问题发生的原因的反馈也将受到赞赏.
重现步骤
https://m.ebay.com/预期行为:应提交搜索表单并显示搜索结果
实际行为:蓝色搜索按钮获得焦点(由明亮的边框表示),但没有其他任何事情发生.
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),我希望这可以与不同的网站一起使用.此外,我不希望网站上的更改破坏我的应用程序.
我想模仿谷歌地图布局.看起来他们使用带有地图片段的协调器布局.问题是:
1 - 我无法设置底视图的最小值(见图1和图3).
2 - 我需要折叠的最大值,我总是希望显示地图的一部分(图2)
3 - 如果我过度折叠地图,FAB和地图会消失.
<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) 我们假设我们有这两个词典:
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)