Android 当键盘显示时,状态栏显示
我的活动使用了CollasingToolbarLayout,我成功地删除了状态栏,执行以下操作:Android 当键盘显示时,状态栏显示,android,android-layout,android-statusbar,Android,Android Layout,Android Statusbar,我的活动使用了CollasingToolbarLayout,我成功地删除了状态栏,执行以下操作: View decorView = getWindow().getDecorView(); // Hide the status bar. int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); 问题是,当软键盘弹出时,状态栏会再次出现,占用宝贵的空间 如何将其永久隐藏在活
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
问题是,当软键盘弹出时,状态栏会再次出现,占用宝贵的空间
如何将其永久隐藏在活动视图中
如果我将其设置为全屏,它可以工作,但我松开了SOFT\u INPUT\u ADJUST\u 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>
该活动正在使用NoActionBar方案(在清单上声明)。在样式活动样式中添加此行
<item name="android:windowFullscreen">true</item>
告诉我它是否有效。需要注意的要点:-
1) 一旦清除了UI标志(例如,通过导航离开活动),如果要再次隐藏栏,应用程序需要重置它们。有关如何侦听UI可见性更改以便应用程序能够相应响应的讨论,请参阅更改
2) 设置UI标志的位置会有所不同。如果在活动的onCreate()方法中隐藏系统栏,并且用户按Home键,系统栏将重新出现。当用户重新打开活动时,不会调用onCreate(),因此系统栏将保持可见。如果希望系统UI更改在用户进出活动时保持不变,请在onResume()或onWindowFocusChanged()中设置UI标志
3) 方法setSystemMivibility()只有在从中调用它的视图可见时才有效
4) 离开视图导航会导致清除使用setSystemMivibility()设置的标志
您应该在创建时添加此代码
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
// again hide it
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
}
}
});
工作,但它松开了软输入调整大小参数。我没有使用ScroolView。我会发布布局。不,只是继续滚动。设置全屏不应影响windows行为,但确实会影响。请查找支持此行为的文档。检查。不管怎样,我会查看的,谢谢:)发布你的布局代码
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- everything you already have -->
</LinearLayout>
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
// again hide it
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
}
}
});