点击控件显示软件盘

 import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.LinearLayout;

public class test extends Activity implements OnClickListener {

 Button button;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  LinearLayout me = new LinearLayout(this);
  LinearLayout.LayoutParams my = new LinearLayout.LayoutParams(

  LinearLayout.LayoutParams.WRAP_CONTENT,
    LinearLayout.LayoutParams.WRAP_CONTENT

  );
  button = new Button(this);
  button.setId(123);
  button.setText("ok");
  button.setOnClickListener((android.view.View.OnClickListener) this);
  me.addView(button, my);
  this.setContentView(me);

 }

 public void onClick(View v) {
  
  InputMethodManager m = (InputMethodManager) button.getContext()
    .getSystemService(INPUT_METHOD_SERVICE);
  m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
 }

 @Override
 public void onClick(DialogInterface dialog, int which) {
 }

}

 

 

android隐藏以及显示软键盘
  1. //隐藏软键盘   

 ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);   

  

//显示软键盘,控件可以是EditText,TextView   

((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).showSoftInput(控件, 0);  

     2.利用时间来控制软键盘的弹出实例:

public class MainActivity extends Activity {

private Context context;

private EditText mEditText;

/** Called when the activity is first created. */
@Override
  public void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  context = this;
  mEditText = (EditText) findViewById(R.id.EditText01);
  mEditText.requestFocus();

  Timer timer = new Timer();
  timer.schedule(new TimerTask() {

   @Override
                 public void run() {
               InputMethodManager m = (InputMethodManager) context.getSystemService   (Context.INPUT_METHOD_SERVICE);
              m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
       }

                 }, 1000);
       }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值