2011-01-29 15 views
14

私はRomain Guyのblog postを読んで、ウィンドウの背景とパフォーマンスを設定して、それをエミュレートしようとしています。このような単純な解決策であり、私はなぜこの作業をすることができないのか分かりませんが、活動は指示された背景を拾うのを単に拒否します。Android:設定ウィンドウ起動したアクティビティの背景

私はListViewを持っています。これは、onListItemClickは新しいActivityを起動します。これは、完全にロードするのに3〜5秒かかります。ユーザーが待っている間、実際に準備が整う前にアクティビティを '参照'できるようにwindowBackgroundを描画したいと思います。ここに私のコードです:

立ち上げ活動のための

AndroidManifestスニペット:

<activity 
     android:name=".activity.EditorActivity" 
     android:screenOrientation="portrait" 
     android:windowBackground="@drawable/background_editor"> 

EditorActivityのためのXMLレイアウト:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TextView 
    android:id="@+id/editor" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:text="Editor" /> 
</FrameLayout> 

そして最後に、描画可能マニフェストに設定され、background_editor.xml :

<?xml version="1.0" encoding="utf-8"?> 
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/editor_bg" 
    android:tileMode="repeat" /> 

editor_bgは、彼がdrawable fololdに位置する.pngファイルですr。

最終結果はEditorActivityを立ち上げますされ、そして私が見るすべては(私はXMLファイルが正しく読み込まれたことをテストすることを加えた白で表示される「エディタ」のテキストでデフォルト黒い背景である。

Iまた、FrameLayoutとTextViewの背景をandroid:background = "@ android:color/transparent"で透明に設定しようとしましたが、黒の背景にデフォルト設定されていたかもしれないと思っていました。数日、私は何か簡単なものを見逃していると確信しています...私がここで作っている間違いはありませんか?

+1

http://とroid-developers.blogspot.com/2009/03/window-backgrounds-ui-speed.html –

答えて

37

新しいアクティビティをプログラムで起動する前に、ウィンドウの背景を設定してみてください。私はのstyles.xmlにテーマスタイルでこれを宣言した場合、それは私の作品

getWindow().setBackgroundDrawableResource(R.drawable.my_drawable); 
1

<application 
    android:name="com.my_app.pack" 
    android:theme="@style/CustomTheme" > 
... 

<?xml version="1.0" encoding="utf-8"?> 
<resources xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <style name="CustomTheme" parent="android:Theme.Holo.NoActionBar"> 
     <item name="android:windowBackground">@color/bg_evening</item> 
    </style> 

</resources> 

とマニフェストに私は自分のアプリケーションにこのテーマを設定し

私の活動の一つに:

<activity 
    android:name="..." 
    android:theme="@style/CustomTheme"> 
... 

あなたは多くのテーマスタイルを宣言して、それらのいずれかを自分のアクティビティに追加することができます。これはアプリケーションに設定されたテーマを上書きします。

2

私は同じ問題に遭遇し、私の場合のように、Javaでテーマを設定することはできません。私のスプラッシュアクティビティを非常に遅く作成しました。その時間まで黒い画面が表示されたままになります。

これは、私たちがマニフェストで指定したテーマからウィンドウを管理する必要があるという手がかりを与えました。

<activity 
     android:name=".main.activities.SplashScreen" 
     android:theme="@style/Splash" 
     android:screenOrientation="portrait"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
</activity> 

次のように今私が作成したテーマは次のとおりです:私が持っているマニフェストあり

ビットマップリソースが含まれている描画可能リソースで

<style name="Splash" parent="@style/Theme.AppCompat.Light"> 
    <item name="android:windowBackground">@drawable/splash</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="windowNoTitle">true</item> 
    <item name="colorPrimaryDark">@color/green_09</item> 
    <item name="colorPrimary">@color/green_09</item> 
    <item name="windowActionBar">false</item> 
</style> 

スプラッシュは、私は微調整する必要がありますビットは、それが完全に伸ばして中央に見えないようにする:

<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:antialias="true" 
    android:dither="true" 
    android:gravity="fill" 
    android:src="@drawable/splash_screen" /> 
関連する問題