RomainGuyのブログ投稿AndroidPerformanceCase Studyに基づいて、Overdrawについて話しているとき、彼は次のように述べています。
ウィンドウの背景の削除:テーマで定義された背景は、アプリケーションの起動時にプレビューウィンドウを作成するためにシステムによって使用されます。アプリケーションが透過的でない限り、nullに設定しないでください。代わりに、getWindow()。setBackgroundDrawable(null)。***を呼び出して、必要な色/画像に設定するか、onCreate()から削除してください。
ただし、getWindow()。setBackgroundDrawable(null)は効果がないようです。コードのサンプルは次のとおりです。
//MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().setBackgroundDrawable(null);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
// main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="#FFE0FFE0"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="#FFFFFFE0" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="@string/hello_world" />
</LinearLayout>
// styles.xml
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">@color/yellow</item>
</style>
このサンプルは、画像に結果を生成します。外層にオーバードローがあり、ウィンドウの背景色がまだ表示されていることがわかります。ウィンドウの背景がなくなり、lineralayoutだけがオーバードローになると予想しました。