基类里面加toolBar后,子类的recyclerView/scrollView里面item的edittext 软键盘遮挡问题

最近遇到的一个问题,基类里面有toolbar,子类里面recyclerView/scrollView里面item的edittext 软键盘被遮挡;

测试了,没有加toolbar的activity没有问题,不会遮挡;

toolbar直接加在activity里面,没问题,不会遮挡;

但是,toolbar放基类里面,就会出现问题。

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

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="visible">

        <ImageView
            android:id="@+id/iv_bg_bar"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@color/toolbar"
            android:scaleType="centerCrop"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/tool_bar"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <TextView
                android:id="@+id/tv_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:text="全屏"
                android:textColor="#FFFFFF"
                android:textSize="18sp"
                android:textStyle="bold"/>

        </android.support.v7.widget.Toolbar>
    </RelativeLayout>

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

</LinearLayout>

解决:

在基类或者子类的oncreate里面加:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN |
        WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

 

SOFT_INPUT_ADJUST_PAN 是调整窗口视图,避免遮挡; SOFT_INPUT_STATE_ALWAYS_HIDDEN 是防止一进来activity就弹出软键盘的.
/** Adjustment option for {@link #softInputMode}: set to have a window
 * pan when an input method is
 * shown, so it doesn't need to deal with resizing but just panned
 * by the framework to ensure the current input focus is visible.  This
 * can <em>not</em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if
 * neither of these are set, then the system will try to pick one or
 * the other depending on the contents of the window.
 */

要加在oncreate里面才可以,在manifest里面加这个属性没有作用

<activity
            android:name="***"
            android:configChanges="keyboard"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateVisible|adjustResize"/>

一个博客:

如何解决软键盘弹出引起的各种不适

http://unicorn25.iteye.com/blog/916504

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值