Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes. In short. Not a great idea but technically feasible. Let me walk you through a quick sample project, adapted from the SoftKeyboard sample included with the android SDK. Now there are a number of other technical issues to tackle but this should provide you with a basic starting point....</p> <p>For starters, lets create a basic layout to use as our keyboard:</p> <p><em><strong>\res\layout\input.xml:</em></strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;WebView android:id="@+id/myWebView" android:layout_width="match_parent" android:layout_height="600dp" /&gt; &lt;/FrameLayout&gt; </code></pre> <p>this is required by android to accept our IME</p> <p><em><strong>\res\xml\method.xml:</em></strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;input-method xmlns:android="http://schemas.android.com/apk/res/android" /&gt; </code></pre> <p>now onto our manifest <strong><em>\AndroidManifest.xml</em></strong></p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.softkeyboard"&gt; &lt;uses-sdk android:minSdkVersion="13" android:targetSdkVersion="13" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;application android:label="SoftKeyboard"&gt; &lt;service android:name="SoftKeyboard" android:permission="android.permission.BIND_INPUT_METHOD" &gt; &lt;intent-filter&gt; &lt;action android:name="android.view.InputMethod" /&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.view.im" android:resource="@xml/method" /&gt; &lt;/service&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>obviously the <code>uses-sdk</code> and <code>user-permission</code> are up to the app and not required by this code (i'm not using any internet files here, but you could, i tested it and it worked...)</p> <p>now define a simple keyboard <strong><em>\src...\SoftKeyboard.java:</em></strong></p> <pre><code>package com.example.android.softkeyboard; import android.inputmethodservice.InputMethodService; import android.inputmethodservice.KeyboardView; import android.view.View; import android.webkit.WebView; public class SoftKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener { private WebView myWebView = null; @Override public View onCreateInputView() { View view = getLayoutInflater().inflate(R.layout.input, null); myWebView = (WebView) view.findViewById(R.id.myWebView); myWebView.getSettings().setJavaScriptEnabled(true); myWebView.addJavascriptInterface(jsInterface, "android"); return view; } private Object jsInterface = new Object() { @SuppressWarnings("unused") public void sendKeys() { getCurrentInputConnection().setComposingText("how do ya like me now?", 1); } }; @Override public void onWindowShown() { super.onWindowShown(); myWebView.loadUrl("file:///android_asset/keyboard_test.html"); } @Override public void onKey(int primaryCode, int[] keyCodes) {} @Override public void onPress(int primaryCode) {} @Override public void onRelease(int primaryCode) {} @Override public void onText(CharSequence text) {} @Override public void swipeDown() {} @Override public void swipeLeft() {} @Override public void swipeRight() {} @Override public void swipeUp() {} } </code></pre> <p>here we basically create a webview then populate it from a asset file and bind a simple interface to it after enabling javascript</p> <p>here's the asset html: <strong>*\assets\keyboard_test.html*</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;test&lt;/title&gt; &lt;style&gt; button { display:block; margin:300px auto; width:400px; padding:60px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;button onclick="android.sendKeys()"&gt;yeah buddy!&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and that's it, run it and you'll get a keyboard with a single button and when you push it the javascript will send text into the input composer... </p> <p>hope that helps -ck</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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