EditText切換IME軟體的enter按鍵,實現跳到下一個EditText或搜尋等,edittextenter

來源:互聯網
上載者:User

EditText切換IME軟體的enter按鍵,實現跳到下一個EditText或搜尋等,edittextenter

 首先,IME軟體的enter鍵其實是可以變的,可以變next,搜尋等等

 例如:實現一個登陸介面

 代碼如下: 

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"><EditText

android:id="@+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="username"
android:imeOptions="actionNext"
android:nextFocusForward="@+id/et_password"
android:singleLine="true"
/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="password"
android:imeOptions="actionDone"
android:layout_below="@id/et_username"
android:nextFocusForward="@+id/btn_login"
android:singleLine="true"
/>
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="login"
android:layout_below="@id/et_password"
/>
</RelativeLayout>

 

android:imeOptions="actionNext"   //這個屬性可以指定IMEenter的功能,actionNext - 下一步    actionSearch 等等

  android:nextFocusForward="@+id/et_password" //指定下一個view 取得焦點

  這樣當你在輸入username 後,按下IME的下一步,就會調到password的輸入框裡。 (這個兩個屬性是父類view的屬性,so)

 

  當你輸完密碼,password的EditText裡有屬性android:imeOptions="actionDone",你也可以實現對它監聽

  代碼如下:

EditText etPassWord = (EditText) findViewById(R.id.et_password);
etPassWord.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  @Override
  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  if(actionId == EditorInfo.IME_ACTION_DONE){
    Toast.makeText(MainActivity.this,"Login",Toast.LENGTH_SHORT).show();
    //...實現login功能
  }
    return false;
  }
});

 

這是我發布的第一個技術部落格,希望大家喜歡,有什麼問題,也希望大家多多交流,共同進步。

以後還會有更多的關於android技術的文章。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.