2015-09-10 8 views
6

मुझे कैसे पता चलेगा कि कीबोर्ड खुला है। असल में मेरी समस्या यह है कि यदि कीबोर्ड खुला है तो केवल मैं छिपाने के लिए कॉल करता हूं, हमेशा कॉल छुपाने के लिए नहीं। यह जांचने के लिए कोई तरीका है कि कीबोर्ड खुला है या नहीं? वर्तमान में मैं कीबोर्ड को छुपाने के लिए इस विधि का उपयोग कर रहा हूं।मुझे कैसे पता चलेगा कि कीबोर्ड खुला है

EditText myEditText = (EditText) findViewById(R.id.myEditText); 
View view = this.getCurrentFocus(); 
if (view != null) {ditText) findViewById(R.id.myEditText); 
View view = this.getCurrentFocus(); 
if (view != null) { Inp` 
im.hideSoftInputFromWindow(view.getWindowToken(), 0); 
+2

क्या आपने http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android की जांच की है? – Rajesh

उत्तर

1

तरह GlobalLayout श्रोता का प्रयास करें:

main_layout.getViewTreeObserver().addOnGlobalLayoutListener(
     new OnGlobalLayoutListener() { 
      @Override 
      public void onGlobalLayout() 
       { 

        Rect r = new Rect(); 
        // r will be populated with the coordinates of your view 
        // that area still visible. 
        main_layout.getWindowVisibleDisplayFrame(r); 

        int heightDiff = main_layout.getRootView().getHeight()-(r.bottom -r.top);  
        //if(hightDiff>100) --> It may be keyboard. 

       } 
}); 

अपने लेआउट के साथ main_layout बदलें।

+2

आप कॉपी और पेस्ट जवाब क्यों दे रहे हैं? आप केवल उत्तर लिंक – Rajesh

+2

पोस्ट कर सकते हैं मैंने आपकी टिप्पणी और लिंक नहीं दिया है ... मैंने पहले इस ऐप में इस ऐप का उपयोग किया है, इसलिए मैंने इसे यहां से रखा है। –

+0

तो क्या यह मार्शमलो पर काम कर रहा है ??? – Pankaj

संबंधित मुद्दे