How to make modification Android Snackbar containing with LayoutInflater button and editText

前端 未结 4 1129
一个人的身影
一个人的身影 2021-01-23 06:36

My project now is how to make a Snackbar displayed at the bottom of the screen. The Snackbar contain with editText and three button for selection categories. I use LayoutInflat

4条回答
  •  迷失自我
    2021-01-23 07:27

    here is the source required to implement button listener to your snackbar custom layout.

    @Override
         public void onClick(View v) {
    
            CoordinatorLayout linearLayout = (CoordinatorLayout)findViewById(R.id.coordinatorLayout);
    
            final Snackbar snackbar = Snackbar.make(linearLayout, "", Snackbar.LENGTH_INDEFINITE);
            Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();
    
            // Inflate your custom view with an Edit Text
            LayoutInflater objLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View snackView = objLayoutInflater.inflate(R.layout.custom_snac_layout, null);
            // custom_snac_layout is your custom xml
    
            // button id for snackbar
            Button button_mapel = (Button) snackView.findViewById(R.id.btn_mapel);
    
            // perform button click listener
            button_mapel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               // here perform your button click task
               }
            });
    
            layout.addView(snackView, 0);
            snackbar.show();
    
        }
    

提交回复
热议问题