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>
在默认启动壁纸秤过,所以我不认为风格问题,但我找不到问题在哪里。