EditText
ユーザーがをタップしたときに画面の下部にキーボードを表示できるようにしようとしていますEditText
。私はInputMethodService
とSoftKeyboardの例を知っていますが、私のキーボードはこれだけで使用できるはずなので、そのように使用することはできませんEditText
。
さらに、コンテキストメニューがあるはずですが、それはこの質問の一部ではありません(私は思います)。
私はたくさんのコードフラグメントを読みましたが、多くの場合、それらにはもう利用できないメソッド(つまり、getViewInflate()
)が含まれているか、理解できない、またはコードに変換できないコンテキストで記述されています( Androidに関する初心者です)。
EditText
ほとんどの場合、 :をタップすると、この例外で失敗します。
java.lang.IllegalArgumentException: width and height must be > 0
その後に、私のクラスを含まないスタックトレースが続きます。以下のコードでわかるように、すべてのサイズが設定されています。
以下に表示されているのは、コードの現在のステータスです(コードの一部を削除しましたが、それでも意味があることを願っています)。また、メインスレッドの内部にあるものを使用しようとしhandler.post()
ましたが、代わりにコメント付きのものを使用しhandler.post()
ます...
RelativeLayout
以下にないのは、EditText
とKeyboardView
を1つのレイアウトで使用する試みです-XML。「無効なタイプ0x12」などの別の例外があり、レイアウトの作成時に何かが発生しました。
それはうまくいかないか、私はそれを行う方法がわかりません。誰かが私にこれを案内してもらえますか?足りないものがあれば教えてください。
main.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>
Keyboard.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"
/>
LatinKeyboardView.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) {
:
}
}