Activity类中:

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

//透明状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//透明导航栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}


Layout布局文件中:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:fitsSystemWindows="true"
android:clipToPadding="true"
android:background="@drawable/test_bg"
android:orientation="horizontal" >