状态栏始终显示在屏幕上
美好的一天(或傍晚或夜晚) 我正在开发针对android的应用程序,我对一件事情非常好奇。我有一个活动,用户与另一个用户聊天,比如“即时通讯”聊天。底部有一个EditText,顶部有一个ActionBar。我需要的是,当用户输入消息并且屏幕上显示软件键盘时,我的活动应该向上移动,但操作栏仍然应该“粘”到屏幕的顶部,因为它有一些有价值的控件。 同样,这不是一个ActionBar,而是一个父级垂直线性布局中的48dp高度布局。所以我需要知道是否有一种简单的方法可以防止布局移出屏幕时移动到顶端。 我试图把一切都放在一个FrameLayout里和放在它上面这个酒吧,但键盘上的AndroidManifest打开它熄灭屏幕太...状态栏始终显示在屏幕上
在你的活动,你应该把这样的:机器人:windowSoftInputMode =” adjustResize”
使用这样的事情:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.myapp.MyActionBar
android:layout_width="match_parent"
android:layout_height="48dp"/>
<LinearLayout
android:id="@+id/mylayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1dp"/>
<!-- Add your edittext and button -->
</LinearLayout>
这将确保在动作条和的EditText +按钮是百达在屏幕上,而mylayout
占据了屏幕的其余部分。显示键盘时,mylayout
会缩小。
尝试为清单中的活动添加android:windowSoftInputMode =“adjustResize”。这告诉Android在键盘出现时完全调整您的布局,而不是平移它。请注意,如果整个布局没有足够的空间,这仍然无法工作。但是如果你的顶层布局是一个RelativeLayout,你应该能够使它工作,编辑文本设置为对齐底部,顶部栏对齐顶部,中间部分为fill_parent并且位于编辑文本的上方,酒吧。
使用的RelativeLayout为您的基地布局,并添加机器人:layout_alignParentTop =“true”以你的动作条,以保持它
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/action_bar_layout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentTop="true" >
</LinearLayout>
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>