Android appcompat toolbar stretches when searchview gets focus

前端 未结 10 1735
猫巷女王i
猫巷女王i 2020-12-08 08:08

I\'m updating an app to use the new Toolbar instead of the regular ActionBar. In my app the user must be able to select a contact from their contac

10条回答
  •  抹茶落季
    2020-12-08 08:43

    The accepted answer works fine, however I needed an alternative that would allow to view the Toolbar under translucent status bar.

    The problem is that Toolbar uses paddings to cover for system components. As a result, the paddingBottom of the Toolbar is being set to soft keyboard's height whenever the keyboard appears. Solution was to reset the padding before calling super.onMeasure in my custom Toolbar class:

    public class MyToolbar extends Toolbar {
    
       (...)
    
       @Override
       protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
           setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), 0);
           super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
    

提交回复
热议问题