android keyboardview 清空,popupwindow - Android: KeyboardView doesn't appear above EditText - Stack Ov...

I'm trying to have an EditText and the possibility to display a keyboard at the bottom of the screen when the user taps the EditText. I'm aware of the InputMethodService and the SoftKeyboard example, but I can't use it in that fashion as my keyboard should only be available to this very EditText.

Furthermore, there should be a context menu, but that's not part of this question (I think).

I've read plenty of code fragments, but in many cases they contain methods that aren't available anymore (i.e., getViewInflate()) 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).

In most attempts I fail with this exception when I tap the EditText:

java.lang.IllegalArgumentException: width and height must be > 0

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.

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 handler.post() in the main thread, use the commented stuff instead of the handler.post() ...

What's not below is an attempt to use a RelativeLayout with the EditText and the KeyboardView in one layout-XML. There was a different exception, something like "invalid type 0x12" or something when creating the layout.

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.

main.xml:

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

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"

/>

keyboard.xml:

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) {

:

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值