Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设置壁纸应用程序android eclipse_Android_Wallpaper - Fatal编程技术网

设置壁纸应用程序android eclipse

设置壁纸应用程序android eclipse,android,wallpaper,Android,Wallpaper,我在eclipse上开发了一个设置手机壁纸的应用程序。该应用程序运行良好,但壁纸模糊。它是我项目的一个组成部分。如果不解决这个问题,我将无法继续 这是密码 MainActivity.java public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onC

我在eclipse上开发了一个设置手机壁纸的应用程序。该应用程序运行良好,但壁纸模糊。它是我项目的一个组成部分。如果不解决这个问题,我将无法继续

这是密码

    MainActivity.java
    public class MainActivity extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Button button =(Button) findViewById(R.id.button1);

            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    startActivity(new Intent("com.example.backgroundapp.bakapp"));
                }
            });
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

    }
The backapp java file
{
    bakapp.java
    public class bakapp extends Activity implements OnClickListener {
        ImageView display;
        int tophone;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);

            // to our activity to cover the whole screen
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);

            setContentView(R.layout.back);
            Button but = (Button) findViewById(R.id.setwallpaper);
            tophone = R.drawable.image4;
            but.setOnClickListener(this);
            display = (ImageView) findViewById(R.id.ivdisplay);
            ImageView image1 = (ImageView) findViewById(R.id.IVimage1);
            ImageView image2 = (ImageView) findViewById(R.id.IVimage2);
            ImageView image3 = (ImageView) findViewById(R.id.IVimage3);
            ImageView image4 = (ImageView) findViewById(R.id.IVimage4);
            ImageView image5 = (ImageView) findViewById(R.id.IVimage5);

            image1.setOnClickListener(this);
            image2.setOnClickListener(this);
            image3.setOnClickListener(this);
            image4.setOnClickListener(this);
            image5.setOnClickListener(this);

        }

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast var;
            switch (v.getId()) {
            case R.id.IVimage1:
                display.setImageResource(R.drawable.n1);
                var = Toast.makeText(bakapp.this, "image changed",
                        Toast.LENGTH_SHORT);

                var.show();

                tophone = R.drawable.n1;
                break;
            case R.id.IVimage2:
                display.setImageResource(R.drawable.n2);
                var = Toast.makeText(bakapp.this, "image changed",
                        Toast.LENGTH_SHORT);

                var.show();

                tophone = R.drawable.n3;
                break;
            case R.id.IVimage3:
                display.setImageResource(R.drawable.n4);
                var = Toast.makeText(bakapp.this, "image changed",
                        Toast.LENGTH_SHORT);

                var.show();

                tophone = R.drawable.n4;
                break;
            case R.id.IVimage4:
                display.setImageResource(R.drawable.n5);
                var = Toast.makeText(bakapp.this, "image changed",
                        Toast.LENGTH_SHORT);

                var.show();

                tophone = R.drawable.n5;
                break;
            case R.id.IVimage5:
                display.setImageResource(R.drawable.n6);
                var = Toast.makeText(bakapp.this, "image changed",
                        Toast.LENGTH_SHORT);

                var.show();

                tophone = R.drawable.n6;
                break;
            case R.id.setwallpaper:
                // to set a background we need to use bitmap
                InputStream is = getResources().openRawResource(tophone);
                // to phone is a variable that is updated everytime we click on an
                // ImageView to that imageview resource and by clicking the button
                // we set the phone background to that image.
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 8;
                Bitmap bm = BitmapFactory.decodeStream(is,null,options);
                // decode inputstream is
                try {
                    getApplicationContext().setWallpaper(bm);
                    // to set the wallpaper of the phone background we need to ask
                    // permission from the user so add permission of background from
                    // manifest file

                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                var = Toast.makeText(bakapp.this, "Wallpaper image changed",
                        Toast.LENGTH_SHORT);

                var.show();

                break;
            }
        }

    }
The layouts are as follows
    main.xml
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Application to Change background picture of device"
            android:textSize="30dp" />

        <Button
            android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="96dp"
            android:text="Click to launch" />

    </RelativeLayout>

    Layout for bakapp.java
    back.xml
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/ivdisplay"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_gravity="center"
            android:src="@drawable/image4" />
    "
        <Button
            android:id="@+id/setwallpaper"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="set image background" >
        </Button>

        <HorizontalScrollView
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/IVimage1"
                    android:layout_width="125dp"
                    android:layout_height="125dp"
                    android:padding="15dp"
                    android:src="@drawable/n1" />

                <ImageView
                    android:id="@+id/IVimage2"
                    android:layout_width="125dp"
                    android:layout_height="125dp"
                    android:padding="15dp"
                    android:src="@drawable/n2" />

                <ImageView
                    android:id="@+id/IVimage3"
                    android:layout_width="125dp"
                    android:layout_height="125dp"
                    android:padding="15dp"
                    android:src="@drawable/n3" />

                <ImageView
                    android:id="@+id/IVimage4"
                    android:layout_width="125dp"
                    android:layout_height="125dp"
                    android:padding="15dp"
                    android:src="@drawable/n4" />

                <ImageView
                    android:id="@+id/IVimage5"
                    android:layout_width="125dp"
                    android:layout_height="125dp"
                    android:padding="15dp"
                    android:src="@drawable/n5" />
            </LinearLayout>
        </HorizontalScrollView>

    </LinearLayout>
MainActivity.java
公共类MainActivity扩展了活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
按钮按钮=(按钮)findViewById(R.id.button1);
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
startActivity(新意图(“com.example.backgroundapp.bakapp”);
}
});
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
}
backapp java文件
{
bakapp.java
公共类bakapp扩展活动实现OnClickListener{
图像视图显示;
内置耳机;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
//让我们的活动覆盖整个屏幕
requestWindowFeature(窗口。功能\u无\u标题);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,
WindowManager.LayoutParams.FLAG(全屏);
setContentView(右布局,背面);
Button but=(Button)findViewById(R.id.setwallpaper);
tophone=R.drawable.image4;
但是.setOnClickListener(这个);
显示=(ImageView)findViewById(R.id.ivdisplay);
ImageView image1=(ImageView)findViewById(R.id.IVimage1);
ImageView image2=(ImageView)findViewById(R.id.IVimage2);
ImageView image3=(ImageView)findViewById(R.id.IVimage3);
ImageView image4=(ImageView)findViewById(R.id.IVimage4);
ImageView image5=(ImageView)findViewById(R.id.IVimage5);
图1.setOnClickListener(此);
图2.setOnClickListener(此);
图3.setOnClickListener(此);
图4.setOnClickListener(此);
图5.setOnClickListener(此);
}
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
吐司变种;
开关(v.getId()){
案例R.id.IVimage1:
display.setImageResource(R.drawable.n1);
var=Toast.makeText(bakapp.this,“图像已更改”,
烤面包片(长/短);
变量show();
tophone=R.drawable.n1;
打破
案例R.id.IVimage2:
display.setImageResource(R.drawable.n2);
var=Toast.makeText(bakapp.this,“图像已更改”,
烤面包片(长/短);
变量show();
tophone=R.drawable.n3;
打破
案例R.id.IVimage3:
display.setImageResource(R.drawable.n4);
var=Toast.makeText(bakapp.this,“图像已更改”,
烤面包片(长/短);
变量show();
tophone=R.drawable.n4;
打破
案例R.id.IVimage4:
display.setImageResource(R.drawable.n5);
var=Toast.makeText(bakapp.this,“图像已更改”,
烤面包片(长/短);
变量show();
tophone=R.drawable.n5;
打破
案例R.id.IVimage5:
display.setImageResource(R.drawable.n6);
var=Toast.makeText(bakapp.this,“图像已更改”,
烤面包片(长/短);
变量show();
tophone=R.drawable.n6;
打破
案例R.id.setwallpaper:
//要设置背景,我们需要使用位图
InputStream is=getResources().openRawResource(tophone);
//to phone是一个变量,每次单击
//ImageView指向该ImageView资源,然后单击按钮
//我们将手机背景设置为该图像。
BitmapFactory.Options=new-BitmapFactory.Options();
options.inSampleSize=8;
位图bm=BitmapFactory.decodeStream(is,null,options);
//解码输入流是
试一试{
getApplicationContext().setWallpaper(bm);
//要设置手机背景的壁纸,我们需要询问
//来自用户的权限,因此添加来自的后台权限
//清单文件
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
var=Toast.makeText(bakapp.this,“壁纸图像已更改”,
烤面包片(长/短);
变量show();
打破
}
}
}
布局如下所示
main.xml
bakapp.java的布局
back.xml
"

options.inSampleSize=8表示原始大小的0.1/8。它可能太小了。您建议使用什么尺寸?我删除了选项。inSampleSize=8,它比以前更好。Thnxx dude