底部菜单栏像whatsapp

时间:2017-12-16 13:07:51

标签: android xml keyboard bottom-sheet

我尝试在聊天应用中实现类似whatsapp的底页。

Menu when Keyboard open Menu when Keyboard close Menu closing effect when keyboard closed Menu closing effect when keyboard open

键盘关闭时,我们点击屏幕上的任意位置,当键盘打开时,它会覆盖菜单,当我们触摸键盘保持打开和关闭菜单的任何地方时。

我像这样在片段中实现底层

public class Menu_BottomSheet extends BottomSheetDialogFragment implements View.OnClickListener {
public static final String TAG="###Bottom###";
BottomSheetBehavior.BottomSheetCallback callback = new BottomSheetBehavior.BottomSheetCallback() {
    @Override
    public void onStateChanged(@NonNull View view, int i) {
        if (i==BottomSheetBehavior.STATE_HIDDEN){
            dismiss();
        }
    }

    @Override
    public void onSlide(@NonNull View view, float v) {

    }
};


@Override
public void setupDialog(Dialog dialog, int style) {
    //super.setupDialog(dialog, style);
    View view=View.inflate(getActivity(), R.layout.menu_bottomsheet,null);
    dialog.setContentView(view);
    TextView button1=view.findViewById(R.id.test1);
    TextView button2=view.findViewById(R.id.test2);
    TextView button3=view.findViewById(R.id.test3);
    TextView button4=view.findViewById(R.id.test4);
    TextView button5=view.findViewById(R.id.test5);
    TextView button6=view.findViewById(R.id.test6);

    button1.setOnClickListener(this);
    button2.setOnClickListener(this);
    button3.setOnClickListener(this);
    button4.setOnClickListener(this);
    button5.setOnClickListener(this);
    button6.setOnClickListener(this);
}

@Override
public void onClick(View view) {

    switch (view.getId()){
        // BOTTOM SHEET MENU CLICK HANDLES
        case R.id.test1:
            Log.d(TAG,"Button 1 Clicked");
            break;

        case R.id.test2:
            Log.d(TAG,"Button 2 Clicked");
            break;

        case R.id.test3:
            Log.d(TAG,"Button 3 Clicked");
            break;

        case R.id.test4:
            Log.d(TAG,"Button 4 Clicked");
            break;

        case R.id.test5:
            Log.d(TAG,"Button 5 Clicked");
            break;

        case R.id.test6:
            Log.d(TAG,"Button 6 Clicked");
            break;
    }

}

在这样的活动中显示底片

Menu_BottomSheet bottomSheet=new Menu_BottomSheet();
            bottomSheet.show(getSupportFragmentManager(),bottomSheet.getTag());

当用打开的键盘按下我的底部纸张关闭键盘时,打开或关闭时它没有平滑的效果。

My bottom sheets

0 个答案:

没有答案