编辑:
似乎像移和ALT键创建影响按下按钮元状态。来自https://developer.android.com/reference/android/view/KeyEvent.html:
元数据状态描述了按键状态,例如META_SHIFT_ON或META_ALT_ON。
这些元状态可以使用dispatchKeyEvent
像这样模拟:
dispatchKeyEvent(new KeyEvent(0,0,KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_L,0,KeyEvent.META_SHIFT_ON));
焦点是一个EditText
这会写“L”进去。但似乎你不仅可以发送KeyEvent
班次,并期望下一个字符为大写。也许你可以想出一些解决方法。
您正在使用和EditText
,对不对?出于某种原因,我不能让
dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT));
时的EditText集中而KeyEvents
的字母和数字的工作工作。
一种解决方法,可以增加一个TextWatcher
到EditText
:
editText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
Log.d(TAG, "afterTextChanged: "+s.toString());
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Log.d(TAG, "beforeTextChanged: "+s.toString());
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.d(TAG, "onTextChanged: "+s.toString());
}
});
,并检查是否CharSequence s
想要的字符afterTextChanged
大写。如果不是,则将其更改为大写版本。这有点冒失,并不完全回答你的问题,但不幸的是,我无法发表评论。
感谢您的答案,没有问题,我也无法评论其他线程。现在到你的答案。是的,我正在使用EditText。那么是不是可以使用dispatchKeyEvent?因为目前我什么都不做。工作并不是我想做的事情。但Google如何在GoogleDocs-Writer中做到这一点? – user7174483