窗口软输入模式不适用于WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS

时间:2017-07-10 11:32:16

标签: android android-layout input android-softkeyboard

我是一个具有渐变效果的自定义状态栏。我使用this解决方案实现了它。主要因素是WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS标志。看看代码...

public class ForgotPasswordActivity extends AppCompatActivity implements Runnable {

    private AppBarLayout appBarLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forgot_password);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) toolbar.getLayoutParams();
        params.height += getStatusBarHeight();
        toolbar.setLayoutParams(params);
        toolbar.setPadding(0, getStatusBarHeight(), 0, 0);
        setSupportActionBar(toolbar);

        // Default settings of the action bar
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            //actionBar.setHomeAsUpIndicator(R.mipmap.ic_arrow_back_white_24dp);
            //actionBar.setHomeButtonEnabled(true);
            //actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setTitle(0);
        }

        // Adding offset listener to block app bar sliding on touch
        appBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);
        appBarLayout.post(this);          
    }

    public int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }

    @Override
    public void run() {
        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
        AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
        if (behavior != null) {
            behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
                @Override
                public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
                    return false;
                }
            });
        }
    }
}

现在的问题是,软输入键盘覆盖了EditText,如下所示......

Screenshots

即使我也尝试过以下链接,但没有发生任何事情......

我无论如何都要这样做,因为整个主题都依赖于这种方法。那么有没有办法根据键盘调整布局或在没有FLAG_LAYOUT_NO_LIMITS的状态栏中实现渐变?

0 个答案:

没有答案