另外两种Android沉浸式状态栏实现思路

2019-12-10 19:23:06王旭

其实,这样已经解决了我上面提出的两个问题

第二种实现方案
第二种方案是为了解决第一种方案中遇到的奇葩问题,设置了透明属性的界面(聊天及底下评论的框框)不能被系统输入法顶上去,之前写过一篇Android 聊天界面背景图片被输入法“顶上去”问题解析,现在遇到的就是无论如何聊天的输入框都不能被系统输入法顶上去(就是打字看不到输入框),经过一番测试,发现竟然和“ android:fitsSystemWindows="true"
”这个属性有关,加上去输入框就没问题,但自定义的状态栏不能被填充到真正的状态栏位置

另外两种Android沉浸式状态栏实现思路

陷入了两难的境地,加还是不加都有问题,而且都特别明显,说了半天,来看看第二种方案。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
 xmlns:android="http://www.easck.com/apk/res/android"
 xmlns:tools="http://www.easck.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@android:color/holo_green_light"
 android:fitsSystemWindows="true"
 tools:context="com.saidtx.myapplication.TestActivity">

 <ScrollView
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_above="@+id/edit"
  android:background="@android:color/white">

  <LinearLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content">

   <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:padding="20dp"
    android:text="@string/previews"/>
  </LinearLayout>
 </ScrollView>

 <LinearLayout
  android:id="@+id/edit"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  android:background="@android:color/white">

  <EditText
   android:layout_width="match_parent"
   android:layout_height="wrap_content"/>
 </LinearLayout>

</RelativeLayout>