Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: KeyboardView doesn't appear above EditText
    primarykey
    data
    text
    <p>I'm trying to have an <code>EditText</code> and the possibility to display a keyboard at the bottom of the screen when the user taps the <code>EditText</code>. I'm aware of the <code>InputMethodService</code> and the SoftKeyboard example, but I can't use it in that fashion as my keyboard should only be available to this very <code>EditText</code>.</p> <p>Furthermore, there should be a context menu, but that's not part of this question (I think).</p> <p>I've read plenty of code fragments, but in many cases they contain methods that aren't available anymore (i.e., <code>getViewInflate()</code>) or are written in a context that I don't understand or can't translate into my code (mind that I'm a newbie regarding Android).</p> <p>In most attempts I fail with this exception when I tap the <code>EditText</code>:</p> <pre><code>java.lang.IllegalArgumentException: width and height must be &gt; 0 </code></pre> <p>followed by a stack-trace that doesn't contain any of my classes. As you can see in the code below all sizes are set.</p> <p>What you see below is the current status of the code (I removed some of the code and I hope it still makes sense). I also tried to use what's inside of <code>handler.post()</code> in the main thread, use the commented stuff instead of the <code>handler.post()</code> ...</p> <p>What's not below is an attempt to use a <code>RelativeLayout</code> with the <code>EditText</code> and the <code>KeyboardView</code> in one layout-XML. There was a different exception, something like "invalid type 0x12" or something when creating the layout.</p> <p>It just doesn't work or I just don't know how to do it. Can anyone please guide me through this? Please let me know if something is missing.</p> <p>main.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;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" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>keyboard.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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" /&gt; </code></pre> <p>LatinKeyboardView.java:</p> <pre><code>import android.inputmethodservice.KeyboardView; public class LatinKeyboardView extends KeyboardView { : } </code></pre> <p>EditorActivity.java</p> <pre><code>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) { : } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload