How to capture onclick event in disabled EditText in Android App

后端 未结 2 953
滥情空心
滥情空心 2020-12-30 18:28

I have a EditText which I am presenting as disabled so that user cannot edit the contents and also to avoid popping-up keyboard. But now I want to capture onclick event in t

2条回答
  •  一生所求
    2020-12-30 19:11

    You can make the component unclickable by using.

    editText.setClickable(false);
    

    To make the component look visually disabled by decreasing the Alpha value.

    editText.setAlpha(0.5f);
    

    It will allow you to set an OnTouchListener on your component by which you can perform your desired operations.

    editText.setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            Toast.makeText(getApplicationContext(),"Component is disabled", Toast.LENGTH_SHORT).show();
                            return false;
                        }
                    });
    

提交回复
热议问题