横竖屏不同的默认壁纸

1、frameworks\base\core\res\res\drawable-nodpi 或者 drawable-sw600dp-nodpi 或者drawable-sw700dp-nodpi

添加default_wallpaper_1.jpg文件

2、frameworks\base\core\res\res\values\symbols.xml

++

3、frameworks\base\core\java\android\app\WallpaperManager.java

++import android.content.res.Configuration;

private InputStream openDefaultWallpaperRes(Context context) {
IWallpaperPlugin mWallpaperPlugin = null;
InputStream is = null;
/// M: Init mWallpaperPlugin for Operators @{
try {
mWallpaperPlugin = (IWallpaperPlugin)MediatekClassFactory.createInstance(
IPluginManager.class,
IPluginManager.CREATE_PLUGIN_OBJECT,
context,
IWallpaperPlugin.class.getName(),
null,
IPluginManager.CLASS);
} catch (Exception e) {
Log.e(TAG,"load IWallpaperPlugin exception: ", e);
}
/// @}
if (mWallpaperPlugin == null || mWallpaperPlugin.getPluginResources(context) == null) {
Xlog.d(TAG, “get the wallpaper image from the plug-in”);
++if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)//竖屏的时候
++{
++is = context.getResources().openRawResource(
com.android.internal.R.drawable.default_wallpaper);
++}
++else
++{
++is = context.getResources().openRawResource(
com.android.internal.R.drawable.default_wallpaper_1);
++}
} else {
is = mWallpaperPlugin.getPluginResources(context).openRawResource(
mWallpaperPlugin.getPluginDefaultImage());
}
return is;
}

4、frameworks\base\packages\SystemUI\src\com\android\systemui\ImageWallpaper.java

// Load bitmap if it is not yet loaded or if it was loaded at a different size
            //if (mBackground == null || surfaceDimensionsChanged) {//任何时候都执行
++if (true) {
                if (DEBUG) {
                    Log.d(TAG, "Reloading bitmap: mBackground, bgw, bgh, dw, dh = " +
                            mBackground + ", " +
                            ((mBackground == null) ? 0 : mBackground.getWidth()) + ", " +
                            ((mBackground == null) ? 0 : mBackground.getHeight()) + ", " +
                            dw + ", " + dh);
                }
                mWallpaperManager.forgetLoadedWallpaper();
                updateWallpaperLocked();
————————————————
版权声明:本文为CSDN博主「Michael_LeePP」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u010916467/article/details/45247761
————————————————
版权声明:本文为CSDN博主「Michael_LeePP」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u010916467/article/details/45247761

在Android应用程序中,如果你想实现在主页横竖屏切换壁纸的功能,通常需要以下几个步骤: 1. **获取屏幕方向**:首先,你需要在Activity或者Fragment中注册屏幕旋转监听器(`OrientationEventListener`),以便在屏幕方向改变时获取新的方向。 ```java OrientationEventListener listener = new OrientationEventListener(this) { @Override public void onOrientationChanged(int orientation) { if (orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { // 更新壁纸 } } }; listener.enable(); ``` 2. **设置壁纸资源**:你可以将壁纸作为动态图片资源(`.png`、`.jpg`等)放在res/drawable目录下,并为横竖屏分别创建不同的尺寸资源。例如,对于Landscape模式,可以创建一个更大的横向壁纸(`drawable-land-hdpi`, `drawable-xhdpi`, 等),Portrait则为常规大小(`drawable-port-mdpi`, `drawable-port-hdpi`等)。 3. **更新壁纸**:当检测到横竖屏变化时,根据当前的方向加载相应的壁纸资源作为桌面背景。这可能涉及到设置壁纸适配器(如`WallpaperManager`)或直接修改Activity的背景图片。 ```java Resources resources = getResources(); int landscapeId = resources.getIdentifier("wallpaper_landscape", "drawable", getPackageName()); int portraitId = resources.getIdentifier("wallpaper_portrait", "drawable", getPackageName()); if (isLandscape()) { WallpaperManager wallpaperManager = WallpaperManager.getInstance(context); wallpaperManager.setResource(landscapeId); } else { wallpaperManager.setResource(portraitId); } ``` 4. **考虑性能**:频繁地更改壁纸可能会对性能造成影响,所以最好设计成只有在用户手动切换或在特定条件下才更换壁纸
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值