我使用CollapsingToolbarLayout组件,并成功地移除了StatusBar
,方法如下:
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
问题在于当软键盘弹出时,状态栏再次出现,占用了宝贵的空间。如何在ActivityView上永久隐藏它?
如果我将其设置为FullScreen,它可以工作,但我失去了SOFT_INPUT_ADJUST_RESIZE参数。主窗口在软键盘出现时滚动,而不是按需要调整大小。
更新:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/my_appar"
android:fitsSystemWindows="false"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/white">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:toolbarId="@+id/collapsetoolbar"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
app:layout_scrollInterpolator="@android:anim/decelerate_interpolator"
app:contentScrim="?attr/colorPrimary">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:elevation="4dp"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="... .MyActivity"
android:orientation="vertical"
>
<FrameLayout
android:id="@+id/yt_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
...
</FrameLayout>
<com.byte_artisan.mchat.compoundViews.chatview.ChatView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/fragment1"
android:id="@+id/chat_view_id">
</com.byte_artisan.mchat.compoundViews.chatview.ChatView>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mchat);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
..
}
@Override
protected void onResume() {
super.onResume();
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
该活动正在使用在清单文件中声明的NoActionBar主题。