无法获取设置按钮,显示动态壁纸 [英] Can't get settings button to display for live wallpaper

查看:184
本文介绍了无法获取设置按钮,显示动态壁纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要设置添加到我创建了一个动态壁纸。我失去了一些有关如何共享preferences工作非常基本的。在code和XML是基于多维数据集的动态壁纸的例子,我想不通我做错了什么。我的问题是,没有设置按钮显示出来,当我选择我从列表中动态壁纸。仅显示设置壁纸按钮。我怀疑是我搞砸了一些在XML。

I want to add settings to a live wallpaper I created. I am missing something very fundamental about how SharedPreferences work. The code and XML are based on the cube live wallpaper example and I can’t figure out what I did wrong. My problem is that no "Settings" button shows up when I choose my live wallpaper from the list. Only the "Set Wallpaper" button is displayed. I suspect that I screwed up something in the XML.

这是一个非常简单的动态壁纸,我刚才用的设置鬼混。它所做的是将背景设置为蓝色或绿色(而该部分作品)。

This is a very simple live wallpaper I made just to fool around with settings. All it does is set the background to either blue or green (and that part works).

我认为是相关的code和XML如下:

What I believe to be the pertinent code and xml follows:

AndroidManifest.xml中

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.BGWallpaper"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />
    <uses-feature android:name="android.software.live_wallpaper" />

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

        <service
            android:icon="@drawable/icon"
            android:label="@string/AppName"
            android:name="com.android.BGWallpaper.BlueGreen"
            android:permission="android.permission.BIND_WALLPAPER" android:debuggable="false">
            <intent-filter android:priority="1">
                <action android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter>
            <meta-data android:name="android.service.wallpaper" android:resource="@xml/bg" />
        </service>
        <activity
            android:label="BGSettings"
            android:name="com.android.BGWallpaper.BGPrefs"
            android:theme="@android:style/Theme.Light.WallpaperSettings"
            android:exported="true">
        </activity>
    </application>
</manifest>

preferences.xml:

Preferences.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
        android:title="Title Preference"
        android:key="BGSettings">
    <ListPreference
            android:key="background"
            android:title="Background Title"
            android:summary="Background Summary"
            android:entries="@array/BackgroundChoices"
            android:entryValues="@array/BackgroundChoices" />
</PreferenceScreen>

bg.xml

bg.xml

<?xml version="1.0" encoding="utf-8"?>
<wallpaper 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:thumbnail="@drawable/icon"/>

BlueGreen.java(壁纸服务)

BlueGreen.java (the wallpaper service)

public class BlueGreen extends WallpaperService 
{
    public static final String strSharedPrefs="BGSettings";

   @Override
    public Engine onCreateEngine() 
    {
         return new BGEngine();
    }

    class BGEngine extends Engine  implements SharedPreferences.OnSharedPreferenceChangeListener
    {
        private SharedPreferences msPrefs;

        private final Runnable mDraw = new Runnable() 
        {
            public void run() 
            {
                draw();
           }
        };

        BGEngine()
        {
            msPrefs = BlueGreen.this.getSharedPreferences(strSharedPrefs, MODE_PRIVATE);
            msPrefs.registerOnSharedPreferenceChangeListener(this);
            onSharedPreferenceChanged(msPrefs, null);
        }
    }
    // ...
}

BG prefs.java:

BGPrefs.java:

public class BGPrefs extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener 
{    
    @Override
    protected void onCreate(Bundle icicle) 
    {
        super.onCreate(icicle);
        getPreferenceManager().setSharedPreferencesName(BlueGreen.strSharedPrefs);
        addPreferencesFromResource(R.xml.preferences);
        getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);    
    }
    // ...
}

所以我缺少什么?

So what am I missing?

另外,我的XML / code部分是被吃掉的自动格式化。有没有办法把它处理文本的文字块,因此它不会格式化吗?

Also, part of my XML/code is being eaten by the automatic formatting. Is there a way to have it treat a block of text as literal so it doesn't format it?

推荐答案

在您的bg.xml ...

In your bg.xml...

<?xml version="1.0" encoding="utf-8"?>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="something"
    android:thumbnail="@drawable/icon"
    android:description="something"
    android:settingsActivity="com.android.BGWallpaper.BGPrefs">
</wallpaper>

安卓settingsActivity是,你需要设置对你的动态壁纸的XML文件中的参数

android:settingsActivity is the param that you need to set against your live wallpaper XML file.

祝你好运:)

这篇关于无法获取设置按钮,显示动态壁纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆