Thursday, 6 February 2014

EditText hidden / covers by keyboard? Fast solution

My problem was about hidding EditText by keyboard. What is more EditText was in activity with theme for Dialog.

What I did to fix was adding this text before setContentView(...);

 getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);  

How ever even in scrollview you are not able to scroll...

---

You can also move big layout to scrollview and set it to scroll to EditText position. In this example my layout has few EditTexts and my last one at the bottom has problem with keyboard, so I did something like this:

 myEditText.setOnTouchListener(new View.OnTouchListener() {  
       @Override  
       public boolean onTouch(View view, MotionEvent motionEvent) {  
         if(view.getId() == R.id.myEditText)  
         {  
           Handler handler = new Handler();  
           handler.postDelayed(new Runnable() {  
             @Override  
             public void run() {  
               scrollview.scrollTo(0, myEditText.getBottom()+300);  
             }  
           }, 300);  
         }  
         return false;  
       }  
     });