2016-10-03 470 views
1

嘿,當我點擊自定義鍵盤時,我可以在鍵盤上每次取消這個白色空白的東西,它向我展示了這個空白的東西,我不想每次都出現我點擊按鈕我如何刪除這個東西它是在畫面,如果你看到它你也會更多,感謝理解我幫助當我點擊一個按鈕

enter image description here

CustomKeyboardView.class

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); 
     } 
    }); 

    startAnimation(animation); 
} 

mainactivity.class

private CustomKeyboardView mKeyboardView; 
private EditText mTargetView; 
private Keyboard mKeyboard; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.main); 
    mKeyboard = new Keyboard(this, R.xml.keyboard); 
    mTargetView = (EditText) findViewById(R.id.target); 
    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(KeyboardWidgetActivity.this, 
         R.anim.slide_in_bottom); 
     mKeyboardView.showWithAnimation(animation); 
    } 
} 

BasicOnKeyboardActionListener.class

public class BasicOnKeyboardActionListener implements KeyboardView.OnKeyboardActionListener { 

private Activity mTargetActivity; 



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); 
} 

回答

2

設置

mKeyboardView.setPreviewEnabled(false); 

+0

感謝設置findViewById您keyboardview後,它的工作 – CJS

+0

等待5分鐘,要做到這一點笑 – CJS

+0

@MikeB:好吧! :) – Jai