▼Androidメモ▼
壁紙の変更


壁紙の変更を行うプログラムを作成する。



ソースコード
WallpaperEx.java
package net.npaka.wallpaperex;
import android.app.Activity;
import android.content.Intent;
import android.graphics.*;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;

//壁紙の変更
public class WallpaperEx extends Activity 
    implements View.OnClickListener {
    private final static int WC=LinearLayout.LayoutParams.WRAP_CONTENT;
    
    //初期化
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        //レイアウトの生成
        LinearLayout layout=new LinearLayout(this);
        layout.setBackgroundColor(Color.TRANSPARENT);
        layout.setOrientation(LinearLayout.VERTICAL);
        setContentView(layout); 
                
        //ボタンの生成
        Button button=new Button(this);
        button.setText("壁紙変更");
        button.setOnClickListener(this); 
        button.setLayoutParams(new LinearLayout.LayoutParams(WC,WC));
        layout.addView(button);
    }
    
    //ボタンクリック時に呼ばれる
    public void onClick(View v) {
        //壁紙変更
        Intent pickWallpaper=new Intent(
            Intent.ACTION_SET_WALLPAPER);
        startActivity(Intent.createChooser(
            pickWallpaper,getString(R.string.app_name)));
    }
}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.npaka.wallpaperex"
    android:versionCode="1"
    android:versionName="1.0">
    <application 
        android:icon="@drawable/icon" 
        android:label="@string/app_name">

        <activity 
            android:name=".WallpaperEx"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Wallpaper">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="7" />

</manifest> 




−戻る−