【问题标题】:How to make directly show live wallpaper in main activity?如何在主要活动中直接显示动态壁纸?
【发布时间】:2014-05-12 23:43:55
【问题描述】:

如何在android的主要活动中直接显示动态壁纸?

我想要一个屏幕,

示例:

当我点击程序时,我想引导动态壁纸“设置壁纸”动态屏幕:

请看图片示例 ![在此处输入图片说明][1]

http://i.stack.imgur.com/IFzTy.png

我不想要壁纸列表,我不想要主活动其他按钮..我只想要当我点击程序时我想要直接动态壁纸“设置壁纸”动态屏幕。

对不起,我的英语不好..

我该怎么办? 请帮帮我

我总共有 4 个 java 代码:

Animationwallpaper.java Bokehrainbowcircle.java Bokehrainbowwallpaper.java MainActivity.Java

And My manifest code:

<?xml version="1.0" encoding="utf-8"?>

<manifest
   xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.sample.livewallpaper.bokehrainbow" android:versionCode="1"
           android:versionName="1.0">

    <uses-sdk android:minSdkVersion="7" />
    <uses-feature android:name="android.software.live_wallpaper" />

    <!-- We need to request a permission to install a shortcut icon -->
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

    <application
       android:label="@string/wallpapers"
       android:icon="@drawable/icon">

        <service

           android:name="com.funnyphotoshoppictures.BokehRainbowWallpaper"
           android:permission="android.permission.BIND_WALLPAPER">
            <intent-filter>
                <action android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter>
            <meta-data android:name="android.service.wallpaper" android:resource="@layout/bokeh" />
        </service>


        <activity

           android:name="com.funnyphotoshoppictures.AnimationWallpaper"
           android:theme="@android:style/Theme.WallpaperSettings"
           android:exported="true">
        </activity>

        <!-- Register the activity in the manifest -->
        <activity
           android:name="com.funnyphotoshoppictures.MainActivity"
           android:theme="@android:style/Theme.WallpaperSettings"
           android:screenOrientation="portrait"
           android:icon="@drawable/icon">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <supports-screens
       android:smallScreens="false"
       android:normalScreens="true"
       android:largeScreens="true" />
</manifest>

【问题讨论】:

    标签: live wallpaper


    【解决方案1】:

    按下按钮后,执行这些代码。 “尝试”中的代码意味着完全跳转到您的目标动态壁纸,而不是您所有动态壁纸的画廊。它似乎满足了您的要求,但它只适用于 >android 4.1。

    “catch”中的代码表示如果手机不支持“try”中的代码,则跳转到所有动态壁纸的图库。

    希望对你有帮助:)

    try{
           Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
           intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
            new ComponentName(MainActivity.this, com.abc.YourMainProgram.class));
           startActivity(intent);
    }
    catch(Exception e){
            Intent intent = new Intent();
            intent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
            startActivity(intent);
    }
    

    【讨论】:

      【解决方案2】:

      在你的styles.xml中使用它:

      <!-- Base application theme. -->
      <style name="AppTheme" parent="Theme.AppCompat">
          <item name="android:windowBackground">@android:color/transparent</item>
          <item name="android:colorBackgroundCacheHint">@null</item>
          <item name="android:windowShowWallpaper">true</item>
          <item name="android:windowTranslucentNavigation">true</item>
          <item name="android:windowTranslucentStatus">true</item>
      </style>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-05
        相关资源
        最近更新 更多