2013-03-26 58 views
0

我已在'xml'文件夾下的keyboard.xml文件中定義了CustomKeyBoard,並在activity_layout.xml中添加了此keyboard.xml。我希望我的CustomkKeyboard應該在我的活動開始時自動加載,但是當我觸摸EditText時它正在加載。我的代碼是自動加載自定義鍵盤而無需觸摸Android中的EditText

private CustomKeyboardView mKeyboardView; 
private View mTargetView; 
private Keyboard mKeyboard; 
mKeyboard = new Keyboard(this, R.xml.keyboard); 
    mTargetView = (EditText) findViewById(R.id.ed_2d_res); 
    mTargetView.setFocusable(true); 
    mTargetView.setOnTouchListener(new View.OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      showKeyboardWithAnimation(); 
      return true; 
     } 
    }); 

    mKeyboardView = (CustomKeyboardView) findViewById(R.id.keyboard_view); 
    mKeyboardView.setKeyboard(mKeyboard); 
    mKeyboardView.setOnKeyboardActionListener(new BasicOnKeyboardActionListener(this)); 
} 

private void showKeyboardWithAnimation() { 
    if (mKeyboardView.getVisibility() == View.GONE) { 
     Animation animation = AnimationUtils.loadAnimation(Add2d.this, R.anim.slide_in_bottom); 
     mKeyboardView.showWithAnimation(animation); 
    } 
} 

是否有任何方式來加載自定義鍵盤與觸摸edittext?

+0

直接從onCreate()調用'showKeyboardWithAnimation();'? – 2013-03-26 17:57:08

回答

0

你可以調用showKeyboardWithAnimation()中的onCreate()的活動的方法,你也應該調用edittext.requestfocus()

+0

這並沒有幫助。 – Bangaram 2013-03-28 04:54:10

0

動畫開始在具有焦點的看法。重寫`onWindowFocusChanged(boolean hasFocus)。

+0

非常感謝。幫助很多。 – Bangaram 2013-03-28 04:53:27