当键盘出现时,BottomNavigationView上移

5

图片

我的BottomNavigationView运行良好,但当我点击EditText进行书写时,它会上移。上面链接中有一张图片。

这是我的清单文件,在其中包含了 android:windowSoftInputMode="adjustPan" 但对我无效。还有其他建议吗?

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:windowSoftInputMode="adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

我的xml文件:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:design="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.segunfamisa.sample.bottomnav.MainActivity">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/mainToolbar"
        android:background="#ffffff"
        android:titleTextColor="#ffffff">
    </android.support.v7.widget.Toolbar>

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@drawable/shadow_top"/>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#ffffff">

    </FrameLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@drawable/shadow"/>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        design:menu="@menu/bottom_nav_items"
        design:itemIconTint="@drawable/selector"
        design:itemTextColor="@drawable/selector"
        android:background="#000000" />
</LinearLayout>

你需要使用一个CoordinatorLayout - Matias Elorriaga
你找到解决方案了吗? - Felipe A.
1
我在manifest文件中的windowSoftInputMode上使用了adjust resize,并且在我的MainActivity中添加了getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); @FelipeA。 - Matias Nagore
@MatiasNagore,我也做了同样的事情,而且非常成功! - Felipe A.
2个回答

17
在您的AndroidManifest.xml文件中,为包含BottomNavigationView的活动添加以下内容:android:windowSoftInputMode="adjustPan"。请注意保留所有HTML标签。

3

你只需要像这样在你的清单文件中添加这段代码即可:

 <activity android:name=".MainActivity"
        android:windowSoftInputMode="adjustPan">

这对我来说很有效...愉快的编码

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