[英]dialog.show() crashed InputMethodService?
Sorry for bothering again, but in my Android keyboard I have 很抱歉再次打扰,但是在我的Android键盘中
public class zyz extends InputMethodService
implements KeyboardView.OnKeyboardActionListener {
private LinearLayout mInputView;
@Override public View onCreateInputView() {
mInputView = (LinearLayout) getLayoutInflater().inflate(R.layout.main, null);
AddKeys("/layout.txt");
return mInputView;
}
...
final Dialog dialog = new Dialog(this,R.style.myBackgroundStyle);
...
linLayBtn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
...
dialog.setContentView(R.layout.dialog);
dialog.show();
...
Which is supposed to show a dialog when a button is presses. 按下按钮时应该显示一个对话框。 Yet it crashes the application...
但是它使应用程序崩溃了...
08-30 17:04:41.554: ERROR/AndroidRuntime(15712): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
Any ideas how to fix it? 任何想法如何解决? Thanks!
谢谢!
dialog.xml dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:orientation="horizontal">
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/frame_left" android:id="@+id/frameLeft"></ImageView>
<LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:background="@drawable/frame_center" android:id="@+id/LLdialog4letter">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/bun_r" android:id="@+id/ivDialogLetter" android:layout_marginTop="3px" android:layout_marginRight="9px" android:layout_marginLeft="9px"></ImageView>
</LinearLayout>
<ImageView android:layout_height="wrap_content" android:src="@drawable/frame_right" android:layout_width="wrap_content" android:id="@+id/frameRight"></ImageView>
</LinearLayout>
This will work for you Enjoy 这将为您工作享受
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Make your selection");
builder.setItems(items, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
// Do something with the selection
}
});
AlertDialog alert = builder.create();
Window window = alert.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
lp.token = mInputView.getWindowToken();
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
window.setAttributes(lp);
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
alert.show();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.