2013-02-18 101 views
0

我有EditText,並且當用戶單擊此EditText時需要顯示我的自定義鍵盤。 (我不需要將此鍵盤設置爲默認,只需使用我的editView顯示一次)如何製作它?如何顯示自定義鍵盤

回答

1

在XML中,設置以下

android:inputMethod="com.myapp.mykeyboard" 
+0

? – Leo 2013-02-18 08:00:03

+0

是的。你可以通過代碼在運行時設置它,但是xml更容易。 – 2013-02-18 08:02:21

+0

嗯,它不起作用。我有Android 2.1+,它說「android:inputMethod is deprecated:Use inputType instead」,但我無法將自定義鍵盤設置爲inputType。 – Leo 2013-02-21 08:02:24

1

做一個佈局鍵盤,在你onCreate方法做這樣的事情

setContentView(R.layout.main); 
     // adjusting key regarding window sizes 
     setKeys(); 
     setFrow(); 
     setSrow(); 
     setTrow(); 
     setForow(); 
     mEt = (EditText) findViewById(R.id.xEt); 
     mEt.setOnTouchListener(this); 
     mEt.setOnFocusChangeListener(this); 
     mEt1 = (EditText) findViewById(R.id.et1); 

     mEt1.setOnTouchListener(this); 
     mEt1.setOnFocusChangeListener(this); 
     mEt.setOnClickListener(this); 
     mEt1.setOnClickListener(this); 
     mLayout = (RelativeLayout) findViewById(R.id.xK1); 
     mKLayout = (RelativeLayout) findViewById(R.id.xKeyBoard); 


@Override 
public boolean onTouch(View v, MotionEvent event) { 
    if (v == mEt) { 
     hideDefaultKeyboard(); 
     enableKeyboard(); 

    } 
    if (v == mEt1) { 
     hideDefaultKeyboard(); 
     enableKeyboard(); 

    } 
    return true; 
} 
private void hideDefaultKeyboard() { 
    getWindow().setSoftInputMode(
      WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

} 
private void enableKeyboard() { 

    mLayout.setVisibility(RelativeLayout.VISIBLE); 
    mKLayout.setVisibility(RelativeLayout.VISIBLE); 

} 

// Disable customized keyboard 
private void disableKeyboard() { 
    mLayout.setVisibility(RelativeLayout.INVISIBLE); 
    mKLayout.setVisibility(RelativeLayout.INVISIBLE); 

} 
在我的佈局活動