当EditText
用户点击EditText
. 我知道InputMethodService
和 SoftKeyboard 示例,但我不能以这种方式使用它,因为我的键盘应该只适用于此EditText
.
此外,应该有一个上下文菜单,但这不是这个问题的一部分(我认为)。
我已经阅读了大量代码片段,但在许多情况下,它们包含不再可用的方法(getViewInflate()
即'我是关于 Android 的新手)。
在大多数尝试中,当我点击EditText
:
java.lang.IllegalArgumentException: width and height must be > 0
后面是一个不包含我的任何类的堆栈跟踪。正如您在下面的代码中看到的那样,所有尺寸都已设置。
您在下面看到的是代码的当前状态(我删除了一些代码,希望它仍然有意义)。我还尝试使用handler.post()
主线程中的内容,使用注释的内容而不是handler.post()
...
下面没有尝试将 aRelativeLayout
与 the EditText
and the KeyboardView
in one layout-XML 一起使用。在创建布局时有一个不同的例外,例如“无效类型 0x12”或其他内容。
它只是不起作用,或者我只是不知道该怎么做。谁能指导我完成这个?如果缺少某些东西,请告诉我。
主.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="@+id/field_input"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:inputType="textMultiLine|textImeMultiLine"
android:typeface="monospace"
android:gravity="top|left"
android:maxLength="255"
/>
</LinearLayout>
键盘.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.messenger.keyboard.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
拉丁键盘视图.java:
import android.inputmethodservice.KeyboardView;
public class LatinKeyboardView extends KeyboardView {
:
}
EditorActivity.java
import android.app.Activity;
public class EditorActivity extends Activity {
private View keyboardLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
final EditText inputField;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
keyboardLayout = (View)getLayoutInflater().inflate(R.layout.keyboard, null, false);
inputField = (EditText)findViewById(R.id.field_input);
registerForContextMenu(inputField);
inputField.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.input, null, false), 100, 100, true);
PopupWindow pw = new PopupWindow(keyboardLayout, 100, 100, true);
pw.showAtLocation(findViewById(R.id.field_input), Gravity.CENTER, 0, 0);
}
});
/*
if (keyboardLayout.getVisibility() == View.GONE) {
// Show Media Player
TranslateAnimation mAnimUp =
new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, -keyboardLayout.getHeight(),
Animation.RELATIVE_TO_SELF, 0);
mAnimUp.setStartOffset(500);
mAnimUp.setDuration(500);
keyboardLayout.setVisibility(View.VISIBLE);
keyboardLayout.setAnimation(mAnimUp);
}
*/
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
:
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
:
}
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
:
}
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
:
}
}