最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)之軟鍵盤用法實(shí)例分析

 更新時(shí)間:2015年05月28日 11:17:19   作者:imzoer  
這篇文章主要介紹了Android開發(fā)之軟鍵盤用法,實(shí)例分析了Android軟鍵盤的實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開發(fā)中軟鍵盤用法。分享給大家供大家參考。具體如下:

打開軟鍵盤,有兩個(gè)方法。一個(gè)是showSoftInput,一個(gè)是toggleSoftInput。

package com.example.dd; 
import android.app.Activity; 
import android.content.Context; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.inputmethod.InputMethodManager; 
import android.widget.Button; 
import android.widget.EditText; 
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.editText2);
    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;
  }
}

其中show方法在使用之前,必須先讓它的第一個(gè)參數(shù)requestFocus??梢钥磗how方法的注釋:

Synonym for showSoftInput(View, int, ResultReceiver) without a result receiver: explicitly request that the current input method's soft input area be shown to the user, if needed.

最后的 if needed兩個(gè)單詞,意思是說,如果調(diào)用了這個(gè)方法而且確實(shí)是有必要顯示鍵盤的時(shí)候,才會(huì)彈出軟鍵盤。

toggle方法可以隨意的打開和關(guān)閉軟鍵盤。

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

汾西县| 弥勒县| 江油市| 阳春市| 岳西县| 资溪县| 黄龙县| 洛扎县| 高阳县| 宜章县| 镇平县| 安西县| 临邑县| 仙游县| 金川县| 曲松县| 太仓市| 黄山市| 沅江市| 山阴县| 云龙县| 呼和浩特市| 镇雄县| 玉环县| 武功县| 肥西县| 石阡县| 北流市| 兴业县| 夹江县| 柳河县| 泸水县| 霍城县| 峨眉山市| 讷河市| 浠水县| 宜州市| 巴塘县| 靖西县| 广灵县| 乐都县|