Android设置输入框和软键盘动态悬浮
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.liuzheng.admin.myhidden.MainActivity"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal"> <Button
android:id="@+id/butt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="显示" /> <Button
android:id="@+id/butt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="隐藏" /> <EditText
android:id="@+id/edit_text"
android:layout_width="200dp"
android:layout_height="wrap_content" /> </LinearLayout> </RelativeLayout>
public class MainActivity extends AppCompatActivity {
private Button butt1;
private Button butt2;
private EditText edit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit = (EditText) findViewById(R.id.edit_text);
butt1 = (Button) findViewById(R.id.butt1);
butt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//绑定软键盘到EditText
edit.setFocusable(true);
edit.setFocusableInTouchMode(true);
edit.requestFocus();
InputMethodManager inputManager = (InputMethodManager) edit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(edit, 0);
}
});
butt2 = (Button) findViewById(R.id.butt2);
butt2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 去除软键盘显示
edit.clearFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.liuzheng.admin.myhidden"> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>
在 项目的AndroidManifest.xml文件中界面对应的<activity>里加入
android:windowSoftInputMode="adjustResize"
各值的含义: 【A】stateUnspecified:软键盘的状态并没有指定,系统将选择一个合适的状态或依赖于主题的设置 【B】stateUnchanged:当这个activity出现时,软键盘将一直保持在上一个activity里的状态,无论是隐藏还是显示 【C】stateHidden:用户选择activity时,软键盘总是被隐藏 【D】stateAlwaysHidden:当该Activity主窗口获取焦点时,软键盘也总是被隐藏的 【E】stateVisible:软键盘通常是可见的 【F】stateAlwaysVisible:用户选择activity时,软键盘总是显示的状态 【G】adjustUnspecified:默认设置,通常由系统自行决定是隐藏还是显示 【H】adjustResize:该Activity总是调整屏幕的大小以便留出软键盘的空间 【I】adjustPan:当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分
Android设置输入框和软键盘动态悬浮的更多相关文章
- android 弹出的软键盘遮挡住EditText文本框的解决方案
1.android 弹出的软键盘遮挡住EditText文本框的解决方案: 把Activit对应的布局文件filename.xml文件里的控件用比重设置布局.(例如:android:layout_wei ...
- Android中点击隐藏软键盘最佳方法——Android开发之路4
Android中点击隐藏软键盘最佳方法 实现功能:点击EditText,软键盘出现并且不会隐藏,点击或者触摸EditText以外的其他任何区域,软键盘被隐藏: 1.重写dispatchTouchEve ...
- Android App监听软键盘按键的三种方式与改变软键盘右下角确定键样式
actionNone : 回车键,按下后光标到下一行actionGo : Go,actionSearch : 放大镜actionSend : SendactionNext : NextactionDo ...
- Android App监听软键盘按键的三种方式
前言: 我们在android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“GO”按键加载url页面:在点击搜索框的时候,点击右下角的sea ...
- Android App监听软键盘按键的三种方式(转)
最近有类似需求,在csdn上刚好发现,粘贴过来,以防止忘记喽 前言: 我们在android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“G ...
- android:windowSoftInputMode属性使用 软键盘
android:windowSoftInputMode="adjustResize|stateHidden" windowSoftInputMode属性设置值说明. <act ...
- Android view显示在软键盘上方
给EditText外加一个ScrollView,将高度设置统一,并给ScrollView设置属性 android:fillViewport="true". 注:ScrollVie ...
- android显示和隐藏软键盘(转)
显示键盘: EditText editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.request ...
- Android 隐藏、显示软键盘方法
隐藏软键盘的终极方法: public class SoftKeyboardUtil { /** * 隐藏软键盘(只适用于Activity,不适用于Fragment) */ public static ...
随机推荐
- Atom编辑器
Atom介绍 Github的员工Nathan Sobo在Atom的博客中提到:”Sublime和TextMate十分方便,但是扩展性不足:另一方面,Emacs和 Vim扩展性很强却需要学习日程工作中很 ...
- sybase用户管理(创建、授权、删除)
一.登录用户管理:1.创建用户:sp_addlogin loginame, passwd [, defdb] [, deflanguage] [, fullname] [, passwdexp] [, ...
- 如何查看SQLServer数据库每个表占用的空间大小?
如何查看SQLServer数据库每个表占用的空间大小? 创建存储过程: CREATE PROCEDURE [dbo].[sys_viewTableSpace]AS BEGIN SET NOCOUNT ...
- delphi access中SQL根据时间查询
Access数据库虽然功能是差了点,但是有时对一些少量的数据保存很是很方便的,在delphi中也是如此,在查询时免不了要按照日期或 时间作为查询条件,access有些特别. select * from ...
- C++输入和输出
本文转载:blog.csdn.net/zhanghaotian2011/article/details/8868577博客 输入和输出并不是C++语言中的正式组成成分。C和C++本身都没有为输入和输出 ...
- (原)JNI中env->GetByteArrayElements和AndroidBitmap_getInfo的冲突
也不是很确定,前段时间的代码没有出问题,但是今天调试了半天,一直崩溃:vm aborting. 以前的部分代码: JNIEXPORT void JNICALL XXX (JNIEnv* env,job ...
- Android的线程和线程池
---恢复内容开始--- 一.Android线程的形态 (一)AsyncTask解析 AysncTask简介:①.实现上封装了Thread和Handler ②.不适合进行特别耗时的后台任务 Ays ...
- glusterFS的缓存测试
众所周知,glusterFS在客户端有缓存,缓存目的在于提高读性能.那么多个客户端同时对文件进行读写,会不会存在client缓存与server文件不一致的情况?比如client A和client B读 ...
- Candy Sharing Game(hdoj1034)
Problem Description A number of students sit in a circle facing their teacher in the center. Each st ...
- UICollectionView 集合视图用法,自定义Cell
在View里面 //1.创建UICollectionViewFlowLayout UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFl ...