Search code examples
androidstatusbar

Components in the new activity drawn under status bar


I used <item name="android:windowTranslucentStatus">true</item> to make my navigation drawer move behind the status bar. But now when I create a new activity, it makes the whole activity to move behind status bar too (like the textview behind the status bar in the image:

enter image description here

Also I want the status bar color to match the app theme in the new activity.

New activity's java file:

public class AddStudent extends AppCompatActivity {

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

New activity's xml file:

<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>

Solution

  • Add android:fitsSystemWindows="true" to your root LinearLayout.

    See this for a detailed explanation.