1

我建立了我的自定義啓動Android 4.4.2和有一些壁紙的問題。當我設置新的壁紙時,一切都很好,適合屏幕顯示,但重新加載設備後,壁紙會縮放,我會看到唯一的中心部分,即使屏幕尺寸和圖像大小默認情況下也是相同的。 我認爲這是因爲多屏幕模式,但我不確定。現在我每次都使用ACTION_BOOT事件上的Broadcast Receiver重置牆紙,但它提供了一些延遲,看起來並不像一個優雅的解決方案。 我設置和使用這個類重載壁紙:重新啓動後調整壁紙大小

public class WallpaperUtils { 

public static final String PREF_CUSTOM_WALLPAPER = "PREF_CUSTOM_WALLPAPER"; 
public static final String PREF_WALLPAPER_RES = "PREF_WALLPAPER_RES"; 

public static void reloadWallpaper(Context context) { 
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); 
    boolean isCustomWallpaper = prefs.getBoolean(PREF_CUSTOM_WALLPAPER, false); 

    if (isCustomWallpaper) { 
     int wallRes = prefs.getInt(PREF_WALLPAPER_RES, 0); 
     setWallpaper(context, wallRes); 
    } 


} 

public static void setWallpaper(Context context, int wallRes) { 

    WallpaperManager manager = WallpaperManager.getInstance(context.getApplicationContext()); 

    WindowManager window = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 

    DisplayMetrics metrics = new DisplayMetrics(); 
    window.getDefaultDisplay().getMetrics(metrics); 

    int width = metrics.widthPixels; 
    int height = metrics.heightPixels; 

    Bitmap tempBitmap = BitmapFactory.decodeResource(context.getResources(), wallRes); 
    Bitmap bitmap = Bitmap.createScaledBitmap(tempBitmap, width, height, true); 

    manager.setWallpaperOffsetSteps(1, 1); 
    manager.suggestDesiredDimensions(width, height); 

    try { 
     manager.setBitmap(bitmap); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

}

和AndroidManifest主屏幕看起來像:

<activity 
     android:name=".ui.main.MainActivity" 
     android:launchMode="singleTask" 
     android:screenOrientation="landscape" 
     android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.HOME" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

在默認啓動壁紙秤過,所以我不認爲風格問題,但我找不到問題在哪裏。

回答

0

經過對android主題和樣式的研究之後,我會明白髮生了什麼問題。

@android:風格/主題

已被棄用,不建議API 11

後使用,因此,我會在主屏幕活動壁紙上通過調用onStart回調壁紙經理並設置爲主佈局的背景。

相關問題