android判断输入法是否弹出窗口,android – 如何判断输入法选择器是打开还是关闭?...

没有这样的机制可以检查InputMethodPicker是否打开.

但是你可以通过另一种方式检查它,比如使用hasWindowFocus()方法进行检查具有根布局的焦点.

以下是示例代码:

main.xml中

android:id="@+id/mainlayout"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello" />

android:id="@+id/btnPicker"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Picker" />

android:id="@+id/btnCheck"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Stop" />

DemoappActivity.class

public class DemoappActivity extends Activity {

/** Called when the activity is first created. */

Button btn1 , btn2;

InputMethodManager imeManager;

LinearLayout mLayoutRoot;

TimerTask timertask;

Timer timer;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

mLayoutRoot = (LinearLayout)findViewById(R.id.mainlayout);

imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);

btn1 = (Button)findViewById(R.id.btnPicker);

btn1.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

showInputMethodPicker();

}

});

btn2 = (Button)findViewById(R.id.btnCheck);

btn2.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

timer.cancel();

}

});

checkMyWindowHasFocus();

}

@Override

protected void onDestroy() {

timer.cancel();

super.onDestroy();

}

public void checkMyWindowHasFocus()

{

timertask = new TimerTask() {

@Override

public void run() {

System.out.println("has window focus..."+mLayoutRoot.hasWindowFocus());

runOnUiThread(new Runnable() {

@Override

public void run() {

Toast.makeText(getApplicationContext(), "Has focus "+mLayoutRoot.hasWindowFocus(), Toast.LENGTH_SHORT).show();

}

});

}

};

timer = new Timer();

timer.schedule(timertask, 500, 5000);

}

private void showInputMethodPicker() {

if (imeManager != null) {

imeManager.showInputMethodPicker();

} else {

Toast.makeText(this, "Error",Toast.LENGTH_LONG).show();

}

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值