1、edittext的一些属性。用到一个edittext的时候,弹出来的软键盘是全屏的,除了软键盘,输入的容器占据了屏幕剩余的地方。很明显不是我们想要的。

其实只要设置 android:imeOptions:"flagNoExtractUi|flagNoFullscreen"就可以了 。

另外还有 弹出来的软键盘的右下键,也就是enter键怎么自定义设置呢?

首先android:imeOptions可以有以下几种:(下面这段xml属性和常量值抄来的)

(1)actionUnspecified未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED效果:

(2)actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE效果:

(3)actionGo去往,对应常量EditorInfo.IME_ACTION_GO 效果:

(4)actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH效果:

(5)actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND效果:

(6)actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT效果:

(7)actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE效果:


举个例子:加入我们要使用enter键点击了去搜索

也就是说一个edittext的imeOptions属性可以为:

<EditText                android:id="@+id/editText"                android:layout_width="470dp"                android:layout_height="38dp"                android:paddingLeft="8dp"                android:background="@drawable/edittext_shape"                android:ems="10"                android:singleLine="true"                android:imeOptions="actionSearch|flagNoExtractUi|flagNoFullscreen">                <requestFocus />            </EditText>


那么 怎么 在代码中根据常量来使用我们自己的逻辑呢?

et =(EditText)findViewById(R.id.editText);

et.setOnEditorActionListener(new EditText.OnEditorActionListener() {            @Override            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {                Log.i(TAG, "onEditorAction ----------- actionId:" + actionId);                if (actionId == EditorInfo.IME_ACTION_SEARCH) {                    InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);                    onClickListener.onClick(goBtn);                }                return false;            }        });


2、上面是关闭软键盘,打开软键盘,android内部已经封装了:在edittext获取焦点之后,点击enter则弹出软键盘

弹出软键盘的代码:

((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);


3、有时候软键盘弹出来会影响布局:比如顶上去了。。

怎么办?

我们可以在AndroidManifest.xml的Activity标签中设置android:windowSoftInputMode为adjustPan(没有滚动条的android页面),或者adjustResize(有滚动条的android页面)


4、注意这里的edittext属性paddingleft有点技巧,一般输入框前面空几个空格就是它实现的。另外如果需要实现输入框前面有几个字不能被修改可以利用这个属性

还有textview来实现,很不错。

更多相关文章

  1. android XML解析详解(封装好的工具类)
  2. android studio gradle 多渠道打包之完全详解(打包系列教程之四)
  3. Android中TextView和EditView常用属性设置
  4. Qt on Android:图文详解Hello World全过程
  5. 关于设置android:imeOptions属性无效的解决办法
  6. Android的属性Property系统

随机推荐

  1. Android sdk自带的9patch工具(9妹)
  2. Android4.1 无预览拍照
  3. android如何制作出一个简单的聊天app
  4. Android绘图必杀技---Canvas和Drawables
  5. 向大家推荐小专栏《Android 面试指南》,还
  6. Android自定义View,你必须知道的几点
  7. Android ProgressBar 相关设置讲解
  8. 用 Eclipse 开发 Android 应用程序[转]
  9. 谷歌推开发者培训指南 欲提升Android软件
  10. Android应用基础浅析