将键盘顶上去可以通过以下步骤实现:
1. 在 `AndroidManifest.xml` 文件中的 `activity` 标签中添加以下属性:`android:windowSoftInputMode="adjustResize"`。该属性可以保持 Activity 的大小固定,并在键盘弹出时调整窗口大小。
```xml
android:name=".YourActivity" android:windowSoftInputMode="adjustResize" /> ``` 2. 在布局文件的根布局中添加 `android:fitsSystemWindows="true"` 属性。该属性可以确保布局不会被系统窗口(如状态栏和导航栏)覆盖。 ```xml xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> ``` 3. 确保键盘顶上去的相关视图被放置在 `ScrollView` 或 `NestedScrollView` 中。当键盘弹出时,ScrollView 会根据需要自动滚动以保持焦点视图可见。 ```xml android:layout_width="match_parent" android:layout_height="match_parent"> ``` 这样,当键盘弹出时,相关视图和布局会自动调整,以确保焦点视图可见。