2014-03-12 4 views
0

현재 내 클라이언트 요구 사항에 따라 사용자 지정 키보드 작업 중입니다. 한 가지 문제를 제외하고 모든 것은 저에게 잘 작동합니다. 제 문제를 단계별로 명확하게 설명하겠습니다.사용자 지정 키보드 겹침 EditText

  1. 하단에는 2 개의 EditText로 구성된 화면이 있습니다.
  2. Edittext를 클릭하면 KeyBoard가 정상적으로 작동하며 도 값을 입력 할 수 있습니다.
  3. 하지만 내 문제는 keyboard가 중복 된 Edittext이므로 이 필요합니다.
    <activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity> 
    
    매니페스트

    에 일부 시나리오에서 해결할 경우

    Keyboard overlapped Edittext

    : EDITTEXT와

스크린 샷 :

Screen Shot With Edittext

키보드 글고 치기를 중복 617,451,515,

XML을 코드

<?xml version="1.0" encoding="utf-8"?> 
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" 
    android:horizontalGap="0dp" 
    android:keyHeight="50dp" 
    android:keyTextSize="12sp" 
    android:keyWidth="25%p" 
    android:labelTextSize="12sp" 
    android:verticalGap="0dp" > 

    <Row> 

     <Key 
      android:codes="8" 
      android:keyEdgeFlags="left" 
      android:keyLabel="1" /> 

     <Key 
      android:codes="9" 
      android:keyLabel="2" /> 

     <Key 
      android:codes="10" 
      android:keyLabel="3" /> 

     <Key 
      android:codes="69" 
      android:keyEdgeFlags="right" 
      android:keyLabel="-" /> 
    </Row> 

    <Row> 

     <Key 
      android:codes="11" 
      android:keyEdgeFlags="left" 
      android:keyLabel="4" /> 

     <Key 
      android:codes="12" 
      android:keyLabel="5" /> 

     <Key 
      android:codes="13" 
      android:keyLabel="6" /> 

     <Key 
      android:codes="56" 
      android:keyEdgeFlags="right" 
      android:keyLabel="." /> 
    </Row> 

    <Row> 

     <Key 
      android:codes="14" 
      android:keyEdgeFlags="left" 
      android:keyLabel="7" /> 

     <Key 
      android:codes="15" 
      android:keyLabel="8" /> 

     <Key 
      android:codes="16" 
      android:keyLabel="9" /> 

     <Key 
      android:codes="67" 
      android:iconPreview="@drawable/sym_keyboard_delete" 
      android:keyEdgeFlags="right" 
      android:keyIcon="@drawable/sym_keyboard_delete" /> 
    </Row> 

    <Row> 

     <Key 
      android:codes="7" 
      android:keyLabel="0" 
      android:keyWidth="50%p" /> 

     <Key 
      android:codes="66" 
      android:keyEdgeFlags="right" 
      android:keyLabel="Done" 
      android:keyWidth="50%p" /> 
    </Row> 

</Keyboard> 

입니다 그리고 활동에 선언 할 때 내 자바 코드는

public class CustomKeyboardView extends KeyboardView { 

    public CustomKeyboardView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public void showWithAnimation(Animation animation) { 
     animation.setAnimationListener(new AnimationListener() { 

      @Override 
      public void onAnimationStart(Animation animation) { 
       // TODO Auto-generated method stub 

      } 

      @Override 
      public void onAnimationRepeat(Animation animation) { 
       // TODO Auto-generated method stub 

      } 

      @Override 
      public void onAnimationEnd(Animation animation) { 
       setVisibility(View.VISIBLE); 
      } 
     }); 

     setAnimation(animation); 
    } 

public class BasicOnKeyboardActionListener implements OnKeyboardActionListener { 

    private Activity mTargetActivity; 
    /*** 
    * 
    * @param targetActivity 
    *   Activity a cui deve essere girato l'evento 
    *   "pressione di un tasto sulla tastiera" 
    * @param mChangedListener 
    */ 
    public BasicOnKeyboardActionListener(Activity targetActivity) { 
     mTargetActivity = targetActivity; 
    } 

    @Override 
    public void swipeUp() { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void swipeRight() { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void swipeLeft() { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void swipeDown() { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onText(CharSequence text) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onRelease(int primaryCode) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onPress(int primaryCode) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onKey(int primaryCode, int[] keyCodes) { 
     long eventTime = System.currentTimeMillis(); 
     KeyEvent event = new KeyEvent(eventTime, eventTime, 
       KeyEvent.ACTION_DOWN, primaryCode, 0, 0, 0, 0, 
       KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE); 

     mTargetActivity.dispatchKeyEvent(event); 

    } 

입니다

private Keyboard mKeyboard; 
    public CustomKeyboardView mKeyboardView; 

    private void setCustomKeyBoard(){ 

     mKeyboard = new Keyboard(mContext, R.layout.keyboard); 

     mKeyboardView = (CustomKeyboardView) findViewById(R.id.keyboard_view); 
     mKeyboardView.setPreviewEnabled(false); 
     mKeyboardView.setKeyboard(mKeyboard); 


     mKeyboardView.setOnKeyboardActionListener(new BasicOnKeyboardActionListener(this)); 

    } 

숨기기 및 키보드

/** Make the CustomKeyboard visible, and hide the system keyboard for view v. */ 
    public void showCustomKeyboard(View v) { 

     mKeyboardView.setVisibility(View.VISIBLE); 
     mKeyboardView.setEnabled(true); 

     if(v!=null){ 
      ((InputMethodManager)mContext.getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0); 

     } 
    } 

    /** Make the CustomKeyboard invisible. */ 
    public void hideCustomKeyboard() { 
     mKeyboardView.setVisibility(View.GONE); 
     mKeyboardView.setEnabled(false); 

    } 

I CLI를 나는 내 사용자 지정 IME 다음과 같은 코드를 추가와 비슷한 문제가 있었다

답변

2

registerEditText(R.id.edtStop); 

private void registerEditText(int resid) { 

     // Find the EditText 'resid' 
     EditText edittext= (EditText)mTradeCommonFieldsView.findViewById(resid); 

     // Make the custom keyboard appear 
     edittext.setOnFocusChangeListener(new OnFocusChangeListener() { 


      @Override 
      public void onFocusChange(View v, boolean hasFocus) { 

       if(hasFocus){ 

        mTradeActivity.showCustomKeyboard(v); 

       }else{ 
        mTradeActivity.hideCustomKeyboard(); 
       } 
      } 
     }); 
     edittext.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       mTradeActivity.showCustomKeyboard(v); 
      } 
     }); 
     // Disable standard keyboard hard way 
     edittext.setOnTouchListener(new OnTouchListener() { 
      @Override public boolean onTouch(View v, MotionEvent event) { 
       EditText edittext = (EditText) v; 
       int inType = edittext.getInputType();  // Backup the input type 
       edittext.setInputType(InputType.TYPE_NULL); // Disable standard keyboard 
       edittext.onTouchEvent(event);    // Call native handler 
       edittext.setInputType(inType);    // Restore input type 
       return true; // Consume touch event 
      } 
     }); 
     // Disable spell check (hex strings look like words to Android) 
     edittext.setInputType(edittext.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); 
    } 

FOLL을 트리거 글고 다음의 방법에 CK 내 InputMethodService 서브 클래스는, 나를 위해 그것을 고정에 :

@Override public void onComputeInsets(InputMethodService.Insets outInsets) { super.onComputeInsets(outInsets); if (!isFullscreenMode()) { outInsets.contentTopInsets = outInsets.visibleTopInsets; } }

관련 문제