我已将软键盘.java文件复制到我的项目中。我已经在我的视图中弹出了键盘,但有些东西告诉我,除非我想更换键盘,否则我不需要直接在我的项目中使用键盘src文件。我已经注释掉了一些这些文件,键盘仍然弹出。你是否像使用android附带的任何其他类一样使用键盘。
public void record() {
int frequency = 44100;
int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_MONO;
int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/reverseme.pcm");
// Delete any previous recording.
if (file.exists())
file.delete();
// Create the new file.
try {
file.createNewFile();
} catch (Exception e) {
throw new IllegalStateException("Failed to create " + file.toString());
}
try {
// Create a DataOuputStream to write the audio data into the saved file.
os = new FileOutputStream(file);
bos = new BufferedOutputStream(os);
dos = new DataOutputStream(bos);
// Create a new AudioRecord object to record the audio.
//int bufferSize = AudioRecord.getMinBufferSize(frequency, channelConfiguration, audioEncoding);
int bufferSize = AudioRecord.getMinBufferSize(sampleRate, channelConfiguration, audioEncoding);
audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
frequency, channelConfiguration,
audioEncoding, bufferSize);
short[] buffer = new short[bufferSize];
audioRecord.startRecording();
while (isRecording) {
int bufferReadResult = audioRecord.read(buffer, 0, bufferSize);
for (int i = 0; i < bufferReadResult; i++)
dos.writeShort(buffer[i]);
}
} catch (Exception e) {
Log.e("AudioRecord","Recording Failed");
e.printStackTrace();
}
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
im.showSoftInput(this.findViewById(R.id.editText1), InputMethodManager.SHOW_FORCED);
}
答案 0 :(得分:1)
如果您使用的是EditText,当您点按它进行编辑时,键盘会自动弹出。
您无需移植自己的软qwerty版本
显示:
EditText editText = (EditText) findViewById(R.id.youredittext);
InputMethodManager ipmgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
隐藏:
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
ipmgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);
所以我认为你走在正确的轨道上。