失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > android键盘悬浮窗口 Android设置输入框和软键盘动态悬浮

android键盘悬浮窗口 Android设置输入框和软键盘动态悬浮

时间:2023-08-29 13:34:18

相关推荐

android键盘悬浮窗口 Android设置输入框和软键盘动态悬浮

1 <?xml version="1.0" encoding="utf-8"?>

2

3 xmlns:tools="/tools"

4 android:layout_width="match_parent"

5 android:layout_height="match_parent"

6 tools:context="com.liuzheng.admin.myhidden.MainActivity">

7

8

10 android:layout_height="45dp"

11 android:layout_alignParentBottom="true"

12 android:orientation="horizontal">

13

14

16 android:layout_width="wrap_content"

17 android:layout_height="wrap_content"

18 android:focusable="true"

19 android:focusableInTouchMode="true"

20 android:text="显示" />

21

22

24 android:layout_width="wrap_content"

25 android:layout_height="wrap_content"

26 android:text="隐藏" />

27

28

30 android:layout_width="200dp"

31 android:layout_height="wrap_content" />

32

33

34

35

1 public class MainActivity extendsAppCompatActivity {2

3 privateButton butt1;4 privateButton butt2;5 privateEditText edit;6

7 @Override8 protected voidonCreate(Bundle savedInstanceState) {9 super.onCreate(savedInstanceState);10 setContentView(R.layout.activity_main);11 edit =(EditText) findViewById(R.id.edit_text);12 butt1 =(Button) findViewById(R.id.butt1);13 butt1.setOnClickListener(newView.OnClickListener() {14 @Override15 public voidonClick(View view) {16 //绑定软键盘到EditText

17 edit.setFocusable(true);18 edit.setFocusableInTouchMode(true);19 edit.requestFocus();20 InputMethodManager inputManager =(InputMethodManager) edit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);21 inputManager.showSoftInput(edit, 0);22 }23 });24 butt2 =(Button) findViewById(R.id.butt2);25 butt2.setOnClickListener(newView.OnClickListener() {26 @Override27 public voidonClick(View view) {28 //去除软键盘显示

29 edit.clearFocus();30 InputMethodManager imm =(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);31 imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);32 }33 });34 }35 }

1 <?xml version="1.0" encoding="utf-8"?>

2

3 package="com.liuzheng.admin.myhidden">

4

5

7 android:icon="@mipmap/ic_launcher"

8 android:label="@string/app_name"

9 android:supportsRtl="true"

10 android:theme="@style/AppTheme">

11

12 android:windowSoftInputMode="adjustResize">

13

14

15

16

17

18

19

20

21

在 项目的AndroidManifest.xml文件中界面对应的里加入

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:当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分

原文:/rookie-26/p/5920577.html

如果觉得《android键盘悬浮窗口 Android设置输入框和软键盘动态悬浮》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。