日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android进阶之路 - 软键盘中右下角的设置与监听

發布時間:2023/12/20 Android 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android进阶之路 - 软键盘中右下角的设置与监听 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在項目中,多多少少會遇到修改軟鍵盤右下角按鈕的需求,雖然已經寫過幾次,但是還是覺得在這里專心做個筆記比較放心 ~

我的那些軟鍵盤Blog ~

  • Android進階之路 - 常見軟鍵盤操作行為
  • Android進階之路 - 軟鍵盤中右下角的設置與監聽
  • Android進階之路 - 軟鍵盤頂起解決方案
  • Android進階之路 - 監聽軟鍵盤當前狀態,實現布局上移

Catalog

        • xml - 部分實現
        • 功能 - 部分實現
        • 完整實現

Effect :


xml - 部分實現

  • 確定右下角的功能展示鍵盤
android:imeOptions="actionSearch"

補充:常見類型

類型含義
actionGoGo
actionSearch放大鏡
actionSendSend
actionNextNext
actionDone完成
  • 確定當前的EditText條目(自我認為,它的字面是獨立一行)
android:singleLine="true"
  • 完整的單個EditText代碼
<EditTextandroid:layout_width="match_parent"android:layout_height="45dp"android:background="@null"android:hint="搜索"android:imeOptions="actionSearch"android:singleLine="true"/>

功能 - 部分實現

  • 設置動作監聽,如:
mSearch.setOnEditorActionListener(this);
  • 進行動作監聽處理
@Overridepublic boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {boolean state = true;switch (actionId) {case EditorInfo.IME_ACTION_SEARCH:Toast.makeText(this, "軟鍵盤內部 - 搜索", Toast.LENGTH_LONG).show();hintKeyboard();break;default:state = false;break;}return state;}
  • 隱藏鍵盤方法
/*隱藏軟鍵盤*/void hintKeyboard() {InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);if (inputMethodManager.isActive()) {inputMethodManager.hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().getWindowToken(), 0);}}

完整實現

MainActivity :

package com.example.yongliu.keyboard;import android.content.Context; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.KeyEvent; import android.view.View; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast;public class MainActivity extends AppCompatActivity implements View.OnClickListener, TextView.OnEditorActionListener {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);EditText mSearch = findViewById(R.id.search);EditText mNext = findViewById(R.id.next);EditText mDone = findViewById(R.id.done);EditText mGo = findViewById(R.id.go);EditText mSend = findViewById(R.id.send);mSearch.setOnClickListener(this);mNext.setOnClickListener(this);mDone.setOnClickListener(this);mGo.setOnClickListener(this);mSend.setOnClickListener(this);mSearch.setOnEditorActionListener(this);mNext.setOnEditorActionListener(this);mDone.setOnEditorActionListener(this);mGo.setOnEditorActionListener(this);mSend.setOnEditorActionListener(this);}@Overridepublic void onClick(View view) {switch (view.getId()) {case R.id.search:Toast.makeText(this, "搜索 - 點擊", Toast.LENGTH_LONG).show();break;case R.id.next:Toast.makeText(this, "下一步 - 點擊", Toast.LENGTH_LONG).show();break;case R.id.done:Toast.makeText(this, "完成 - 點擊", Toast.LENGTH_LONG).show();break;case R.id.go:Toast.makeText(this, "Go - 點擊", Toast.LENGTH_LONG).show();break;case R.id.send:Toast.makeText(this, "發送 - 點擊", Toast.LENGTH_LONG).show();break;}}@Overridepublic boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {boolean state = true;switch (actionId) {case EditorInfo.IME_ACTION_SEARCH:Toast.makeText(this, "軟鍵盤內部 - 搜索", Toast.LENGTH_LONG).show();hintKeyboard();break;case EditorInfo.IME_ACTION_NEXT:Toast.makeText(this, "軟鍵盤內部 - 下一步", Toast.LENGTH_LONG).show();hintKeyboard();break;case EditorInfo.IME_ACTION_DONE:Toast.makeText(this, "軟鍵盤內部 - 完成", Toast.LENGTH_LONG).show();hintKeyboard();break;case EditorInfo.IME_ACTION_GO:Toast.makeText(this, "軟鍵盤內部 - Go", Toast.LENGTH_LONG).show();hintKeyboard();break;case EditorInfo.IME_ACTION_SEND:Toast.makeText(this, "軟鍵盤內部 - 發送", Toast.LENGTH_LONG).show();hintKeyboard();break;default:state = false;break;}return state;}/*隱藏軟鍵盤*/void hintKeyboard() {InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);if (inputMethodManager.isActive()) {inputMethodManager.hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().getWindowToken(), 0);}} }

MainActivity Xml :

<?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context="com.example.yongliu.keyboard.MainActivity"><TextViewandroid:layout_width="match_parent"android:layout_height="45dp"android:gravity="center"android:text="軟鍵盤監聽"/><EditTextandroid:id="@+id/search"android:layout_width="match_parent"android:layout_height="45dp"android:background="@null"android:gravity="center|start"android:hint="搜索"android:imeOptions="actionSearch"android:paddingLeft="15dp"android:singleLine="true"android:textSize="13sp"/><EditTextandroid:id="@+id/send"android:layout_width="match_parent"android:layout_height="45dp"android:background="@null"android:gravity="center|start"android:hint="發送"android:imeOptions="actionSend"android:paddingLeft="15dp"android:singleLine="true"android:textSize="13sp"/><EditTextandroid:id="@+id/go"android:layout_width="match_parent"android:layout_height="45dp"android:background="@null"android:gravity="center|start"android:hint="Go"android:imeOptions="actionGo"android:paddingLeft="15dp"android:singleLine="true"android:textSize="13sp"/><EditTextandroid:id="@+id/next"android:layout_width="match_parent"android:layout_height="45dp"android:background="@null"android:gravity="center|start"android:hint="下一步"android:imeOptions="actionNext"android:paddingLeft="15dp"android:singleLine="true"android:textSize="13sp"/><EditTextandroid:id="@+id/done"android:layout_width="match_parent"android:layout_height="45dp"android:background="@null"android:gravity="center|start"android:hint="完成"android:imeOptions="actionDone"android:paddingLeft="15dp"android:singleLine="true"android:textSize="13sp"/> </LinearLayout>

總結

以上是生活随笔為你收集整理的Android进阶之路 - 软键盘中右下角的设置与监听的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲一区二区三区四区av | 亚洲精品网站在线观看 | 少妇人妻真实偷人精品视频 | 欧美极品第一页 | 麻豆精品在线视频 | av手机版| 日本成人片网站 | 日韩无套| 国产一区二区三区高清视频 | 日本视频免费在线 | 欧美xx视频 | 天天曰天天爽 | 一二区视频 | 免费小视频在线观看 | 美女啪啪网址 | 99国产精品久久久久99打野战 | 国产一区二区三区亚洲 | 日本va在线观看 | 欧日韩不卡在线视频 | 久久人人超碰 | 中国一级特黄毛片 | 日本女人毛片 | 亚洲av综合色区无码一二三区 | 都市激情校园春色亚洲 | 91精品国产色综合久久不卡蜜臀 | 国产黄色大片 | 成人超碰 | www.夜夜爽| 在线看片日韩 | 亚洲美女色视频 | 97在线精品 | 国产九九精品 | 日本欧美一区二区三区 | 国产成人无码一二三区视频 | 日韩欧美xxxx| 日日干,夜夜操 | 中文字幕丝袜诱惑 | 国产免费高清av | 国产成人av一区 | 毛片毛片毛片毛片毛片毛片毛片毛片毛片毛片 | 色老头av | 草碰在线 | 香蕉国产在线观看 | 成人aaaaa| 成人精品一区二区三区电影 | 免费特黄视频 | 在线免费看污片 | 国产suv精品一区二区33 | 香蕉影院在线观看 | 成人影视在线播放 | 99久免费精品视频在线观78 | 午夜免费在线观看 | 欧美一区二区精品 | 欧美系列第一页 | 波多野42部无码喷潮在线 | 欧美日韩一级在线观看 | 午夜精品福利一区二区 | 毛片1000部免费看 | 色欧美片视频在线观看 | 午夜网站在线观看 | 正在播放av| 久久久夜色精品亚洲 | 91精品国产日韩91久久久久久 | 色偷偷91 | 绯色av一区二区三区高清 | 国产在线一级 | 国产又黄又大又粗视频 | 天堂av中文字幕 | 亚洲一二三区在线观看 | 电影91久久久 | 国产又粗又硬视频 | 国产学生美女无遮拦高潮视频 | 亚洲资源av | 激情小说在线观看 | 国产精品免费一区二区三区四区 | 五月婷婷综 | 国产极品美女高潮无套嗷嗷叫酒店 | 成人欧美一区二区三区黑人一 | 51福利视频 | 98堂 最新网名 | 天天视频黄 | 日韩专区一区二区三区 | 亚洲天堂视频在线播放 | 人妖一区二区三区 | 一区二区免费在线播放 | 精品综合| 亚洲色图欧美另类 | av免费在线观 | 亚洲精品国产精品乱码不66 | 午夜一区二区三区四区 | 毛片亚洲av无码精品国产午夜 | 国产免费一区二区三区在线播放 | 欧美一区二区免费 | 午夜视频在线观看网站 | 欧美日韩国产综合网 | 在线播放国产视频 | 久久精品视频免费观看 | 大地资源二中文在线影视免费观看 | 18精品爽国产白嫩精品 |