溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android軟鍵盤用法實例

發布時間:2020-08-05 18:44:11 來源:網絡 閱讀:354 作者:石望來 欄目:移動開發

package com.example.key;




import android.os.Bundle;

import android.app.Activity;

import android.content.Context;

import android.view.Menu;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.view.View.OnClickListener;

import android.view.inputmethod.InputMethodManager;


public class MainActivity extends Activity {


 @Override

 protected void onCreate(Bundle savedInstanceState) { 

   super.onCreate(savedInstanceState); 

   setContentView(R.layout.activity_main); 

   final EditText ed2 = (EditText) findViewById(R.id.editText1);

   Button b1 = (Button) findViewById(R.id.button1); 

   b1.setOnClickListener(new OnClickListener() { 

     @Override

     public void onClick(View v) { 

       ed2.requestFocus(); 

       show(ed2); 

     } 

   });

   Button b2 = (Button) findViewById(R.id.button2);

   b2.setOnClickListener(new OnClickListener() {

     @Override

     public void onClick(View v) {

       toggle();

     }

   });

 }

 private void show(EditText ed2) {

   InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

   imm.showSoftInput(ed2, InputMethodManager.SHOW_IMPLICIT);

 }

 private void toggle() {

   InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

   imm.toggleSoftInput(0, 0);

 }

 @Override

 public boolean onCreateOptionsMenu(Menu menu) {

   // Inflate the menu; this adds items to the action bar if it is present.

   getMenuInflater().inflate(R.menu.main, menu);

   return true;

 }

}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女