2015-02-12 77 views
2

我有一個包含輸入表單的WebView。 當用戶選擇第一個輸入時,鍵盤出現,並將滾動WebView,以便輸入被揭露。我的問題是在< API 19中點擊下一個部分模糊輸入時WebView不滾動。如果我要關閉鍵盤,然後選擇輸入,它會正確滾動。打開鍵盤時WebView不滾動

我讀過很多關於如果活動是FullScreen,那麼它不會工作,但我的應用程序不是。

清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.app.MyApp"> 

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

    <application 
     android:name=".App" 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme"> 
     <activity 
      android:name="com.app.MyApp.MainActivity" 
      android:configChanges="orientation|keyboardHidden" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" 
      android:windowSoftInputMode="adjustResize|stateVisible"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

的WebView佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:animateLayoutChanges="true" 
    android:orientation="vertical"> 

    <WebView 
     android:id="@+id/banking_webview" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

    <LinearLayout 
     android:id="@+id/banner" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/BannerOrange" 
     android:clickable="true" 
     android:orientation="horizontal" 
     android:padding="2dp" 
     android:visibility="gone"> 

     <ImageView 
      android:id="@+id/banner_image" 
      android:layout_width="64dp" 
      android:layout_height="@dimen/single_line_height" 
      android:scaleType="fitCenter"/> 

     <TextView 
      android:id="@+id/banner_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="@dimen/typography_subhead"/> 
    </LinearLayout> 
</LinearLayout> 

main_activity.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:wheel="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <include 
     android:id="@+id/toolbar_actionbar" 
     layout="@layout/toolbar_default" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/toolbar_actionbar"> 

     <FrameLayout 
      android:id="@+id/container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 

     <fragment 
      android:id="@+id/fragment_drawer" 
      android:name="com.app.MyApp.NavigationDrawerFragment" 
      android:layout_width="@dimen/navigation_drawer_width" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      app:layout="@layout/fragment_navigation_drawer"/> 
    </android.support.v4.widget.DrawerLayout> 
</RelativeLayout> 

回答

-1

將您的WebView佈局滾動型內。這將解決你的問題。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:animateLayoutChanges="true" 
    android:orientation="vertical"> 

    <WebView 
     android:id="@+id/banking_webview" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

    <LinearLayout 
     android:id="@+id/banner" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/BannerOrange" 
     android:clickable="true" 
     android:orientation="horizontal" 
     android:padding="2dp" 
     android:visibility="gone"> 

     <ImageView 
      android:id="@+id/banner_image" 
      android:layout_width="64dp" 
      android:layout_height="@dimen/single_line_height" 
      android:scaleType="fitCenter"/> 

     <TextView 
      android:id="@+id/banner_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="@dimen/typography_subhead"/> 
    </LinearLayout> 
    </LinearLayout> 
</ScrollView> 
+0

不解決問題。事實上,即使第一個選定的字段沒有滾動到。 – 2015-02-22 22:05:28

+0

你能分享你的webview的截圖嗎? – Abhishek 2015-02-23 05:45:46

0

您需要在layout xml中將android:windowSoftInputMode="adjustResize"添加到您的WebView標記中。

0

您需要添加:

的片段/活性佈局文件的
android:fitsSystemWindows="true" 

給你根以及:

在清單
android:windowSoftInputMode="adjustResize" 

到你的活動。