Android软键盘手动显示、隐藏、布局上移和EditText上移
来源:互联网 发布:台达触摸屏编程软件3.0 编辑:程序博客网 时间:2024/05/22 14:03
主要实现:Android软键盘手动显示、隐藏、布局上移和EditText上移
- AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.demo0831" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <!-- 布局整体上移adjustPan|stateHidden --> <!-- 单输入框上移整体adjustResize|stateHidden --> <activity android:name="com.example.demo0831.MainActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustResize|stateHidden" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
- MainActivity.java
package com.example.demo0831;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.view.Window;import android.view.WindowManager;import android.view.inputmethod.InputMethodManager;import android.widget.Button;import android.widget.EditText;public class MainActivity extends Activity { private Button bt_open_keyboard; private EditText et; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // getWindow().setSoftInputMode( // WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); bt_open_keyboard = (Button) findViewById(R.id.bt_open_keyboard); et = (EditText) findViewById(R.id.et); bt_open_keyboard.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 方法一(如果输入法在窗口上已经显示,则隐藏,反之则显示) InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); // 方法二(view为接受软键盘输入的视图,SHOW_FORCED表示强制显示) // InputMethodManager imm = (InputMethodManager) // getSystemService(Context.INPUT_METHOD_SERVICE); // imm.showSoftInput(et, InputMethodManager.SHOW_FORCED); // imm.hideSoftInputFromWindow(et.getWindowToken(), 0); //强制隐藏键盘 } }); }}
- activity_main.xml
<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" android:orientation="vertical" tools:context=".MainActivity" > <Button android:id="@+id/bt_open_keyboard" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <EditText android:id="@+id/et" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_gravity="bottom" /></RelativeLayout>
源码下载地址
0 0
- Android软键盘手动显示、隐藏、布局上移和EditText上移
- android 软键盘弹出 布局上移动
- 软键盘弹出布局与edittext一起上移
- EditText弹出软键盘后布局上移问题
- 软键盘弹出布局上移
- 包含listview和edittext的界面,软键盘打开时布局向上移的解决方案
- 【Android】软键盘弹出button与edittext一起上移
- Android 防止EditText软键盘使键盘上移的方法
- Android软键盘弹出,界面布局整体上移
- Android弹出软键盘布局是否上移问题
- Android监听软键盘,布局上移不遮挡输入框
- Android 手动显示和隐藏软键盘
- Android 手动显示和隐藏软键盘
- Android 手动显示和隐藏软键盘
- Android 手动显示和隐藏软键盘
- Android 手动显示和隐藏软键盘
- Android 手动显示和隐藏软键盘
- Android 手动显示和隐藏软键盘
- cocos2dx-lua用sublime执行exe
- Java开发中的23种设计模式详解(转)
- 两个线程同时调用一个函数会出现什么情况?
- 红黑树
- 10278 FireStation
- Android软键盘手动显示、隐藏、布局上移和EditText上移
- tomcat配置虚拟目录映射
- WEB UI设计尺寸规范
- linux文件目录操作命令 cd
- 转:在华为的工作体验,可以get一些点(仅自娱自乐)
- android之PowerManager 与电源管理,解决灭屏状态下来短信屏幕不会点亮问题
- STA基础分析-setup和hold
- Java笔记整理:一切都是对象
- Android 音量调节View