底部 TabLayout 位于键盘顶部

Posted

技术标签:

【中文标题】底部 TabLayout 位于键盘顶部【英文标题】:Bottom TabLayout comes on top of keyboard 【发布时间】:2019-05-04 23:43:12 【问题描述】:

在我正在设计的应用程序中,我的MainActivity 上有一个底部TabLayoutViewPager

问题是每次我点击需要输入的东西(因此键盘出现)时,TabLayout 都会粘在键盘的顶部。我希望它留在原处 - 这意味着它将被键盘隐藏。

此屏幕截图中表达了问题。我不等待它进入键盘顶部。

我的清单文件在这里(我尝试了adjustNothingadjustPanadjustResize...的各种组合):

<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps android API v2, but you must specify either coarse or fine
     location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:name=".PinUpApplication"
    android:allowBackup="true"
    android:icon="@mipmap/pinup"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/pinup_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:windowSoftInputMode="adjustPan">

    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/.
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity android:name=".Activities.MainActivity"
        android:windowSoftInputMode="adjustPan|adjustResize"
        android:screenOrientation="portrait">
    </activity>
    <activity android:name=".Activities.HorecaActivity"
        android:screenOrientation="portrait"/>
    <activity android:name=".Activities.HorecaMainActivity"
        android:screenOrientation="portrait"/>
    <activity android:name=".Activities.EditProfileActivity"
        android:screenOrientation="portrait"/>
    <activity android:name=".Activities.PersonProfileActivity"
        android:screenOrientation="portrait"/>
    <activity android:name=".Activities.LoginActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Activities.RegisterActivity"
        android:screenOrientation="portrait">
    </activity>
    <activity android:name=".Activities.NoNetworkActivity"
        android:screenOrientation="portrait"></activity>
    <meta-data android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>

    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" />
    <activity
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
    </activity>
</application>

下面是活动的代码:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_
android:layout_
android:fitsSystemWindows="true"
android:background="@color/white">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_
    android:layout_
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <FrameLayout
        android:layout_
        android:layout_
        app:layout_scrollFlags="enterAlways">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_
            android:layout_
            android:windowActionModeOverlay="false"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_search"
            android:layout_
            android:layout_
            android:background="@color/colorPrimary"
            android:gravity="center_vertical"
            android:visibility="gone"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </FrameLayout>

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

<LinearLayout
    android:layout_
    android:layout_
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <ro.ineedhelp.pinup.Utils.NonSwipeableViewPager
        android:id="@+id/viewpager"
        android:layout_
        android:layout_
        android:layout_weight="1" />

</LinearLayout>

<FrameLayout
    android:id="@+id/main_pager"
    android:layout_
    android:layout_
    android:windowSoftInputMode="adjustPan|adjustResize"
    android:layout_gravity="bottom"
    android:layout_alignParentBottom="false">
    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        style="@style/MyCustomTabLayout"
        android:layout_
        android:layout_
        android:background="@color/white"
        app:tabIndicatorColor="@color/colorPrimary"
        app:tabIconTint="@color/grey_600"
        app:tabTextColor="@color/grey_600"/>
</FrameLayout>

<include
    layout="@layout/sheet_activity_map"
    android:layout_
    android:layout_
    android:layout_gravity="bottom"
    app:layout_behavior="@string/bottom_sheet_behavior" />

【问题讨论】:

请不要使用设计标签;它正在被删除。 【参考方案1】:

在清单文件中为您的 Main Activity 试试这个。

android:windowSoftInputMode="stateAlwaysHidden | adjustPan"

【讨论】:

以上是关于底部 TabLayout 位于键盘顶部的主要内容,如果未能解决你的问题,请参考以下文章

Android:键盘打开时出现 Tablayout

如何将tablayout的指示器从底部更改为顶部?

简单Fragment+Tablayout+ViewPage实现底部和顶部滑动(菜单栏)

键盘顶部的对话框

TabLayout实现底部导航栏

将自定义视图附加到 Android 键盘的顶部