【发布时间】:2015-02-22 05:26:11
【问题描述】:
在我的 Android 应用程序中,我有一个 Activity,其布局几乎是 WebView 元素。在这个 WebView 中,我正在加载在线表格供用户填写。但是,底部输入字段(文本框)位于软键盘后面,用户无法填写。
这种情况有哪些可能的解决方案?
这是我的代码:
AndroidManifest.xml(仅此布局部分)
<activity
android:name=".home.SurveyActivity"
android:configChanges="orientation"
android:icon="@drawable/logo_white"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
</activity>
布局文件:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/custom_header"
style="@style/CustomHeader.Height"
android:layout_alignParentTop="true"/>
<WebView
android:id="@+id/activity_portal_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/activity_portal_bottom_layout"
android:layout_below="@id/custom_header"
android:scrollbars="none"/>
<LinearLayout
android:id="@id/activity_portal_bottom_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
活动类:
public class SurveyActivity extends Activity {
public static Intent makeIntent(Context context) {
return new Intent(context, SurveyActivity.class);
}
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Utils.updateLang();
setContentView(R.layout.survey_activity_main);
Utils.inflateCustomHeader(this);
WebView webView = (WebView) findViewById(R.id.activity_portal_webview);
webView.setWebChromeClient(new WebChromeClient());
WebSettings webSettings = webView.getSettings();
webSettings.setLoadsImagesAutomatically(true);
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setDefaultTextEncodingName("UTF-8");
webView.loadUrl("WWW.EXAMPLE.COM");
}
@Override
protected void onResume() {
super.onResume();
Utils.updateLang();
LinearLayout navigationBar = (LinearLayout) findViewById(R.id.activity_portal_bottom_layout);
navigationBar.removeAllViews();
navigationBar.addView(NavigationBarContract.makeNavigationBar(this, R.id.navigation_bar_home_button));
}
}
【问题讨论】:
-
但是网页视图可以滚动,用户可以滚动并移动到特定的输入字段
-
@Fahim 你说得对,我在模拟器上测试时是这样,但在我的 Android 4.4.4 设备 Galaxy A3 上不是这样。
-
你能在 webview 上试试 android:layout_height="wrap_content"
标签: android webview android-webview android-softkeyboard