什么是在Android软键盘顶部附加在XML中定义的布局的最简单方法?该视图应仅在键盘出现时显示。
我认为这是更清晰的方法。
定义一个布局资源文件作为您的自定义视图
创建一个方法,该方法会填充此布局资源文件并将其作为视图返回: 代码片段
public View returnPayKeyView(){
View simpleView = getLayoutInflater().inflate(R.layout.simpleresource,null);
return simpleView;
}
使用setCandidatesView方法将此返回的视图设置为候选项
返回的视图将显示在您的键盘上方,使用填充的xml布局资源。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- all your stuff... -->
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/stuffAboveKeyboardLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:background="#DDD">
<!-- stuff above keyboard... -->
</LinearLayout>
</FrameLayout>
缺点是即使键盘隐藏,它也会显示出来 - 但应该可以在键盘显示/隐藏时显示/隐藏视图:如何检测Android设备上的软件键盘是否可见?
android:windowSoftInputMode="adjustPan"
)。 - Daniel L.