activity 在状态栏下绘制的新组件

Components in the new activity drawn under status bar

我用过<item name="android:windowTranslucentStatus">true</item> 让我的导航抽屉移到状态栏后面。但是现在当我创建一个新的 activity 时,它也会使整个 activity 移动到状态栏后面(就像图像中状态栏后面的文本视图:

我还希望状态栏颜色与新 activity 中的应用主题相匹配。

新 activity 的 java 文件:

public class AddStudent extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_student);
}

新 activity 的 xml 文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.gupta.aayush.tuitionmanager.AddStudent"
android:orientation="vertical">

<TextView
    android:id="@+id/textView4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="TextView" />
</LinearLayout>

android:fitsSystemWindows="true" 添加到您的根 LinearLayout

详细解释