zoukankan      html  css  js  c++  java
  • AS-demo09

    1,mainifast:
    
     <uses-permission android:name="android.permission.SET_WALLPAPER"/>
    
    2,
    
    <LinearLayout 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:orientation="vertical"
    
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".MainActivity">
    
    
    
        <TextView
        android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="长按图片设置为背景"/>
        <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/logo"/>
    </LinearLayout>
    ================================
    
    
    package com.example.demo09longclickchangebg;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.View;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    import java.io.IOException;
    
    public class MainActivity extends Activity {
    
        private TextView textView =null;
        private ImageView imageView = null;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            this.textView=(TextView)super.findViewById(R.id.title);
            this.imageView=(ImageView)super.findViewById(R.id.img);
    
            this.imageView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View view) {
                    try {
                        MainActivity.this.clearWallpaper();
                        MainActivity.this.setWallpaper(MainActivity.this.imageView.getResources().openRawResource(R.drawable.logo));
                        MainActivity.this.textView.setText("手机桌面背景已修改BG changed!");
                    } catch (IOException e) {
                        MainActivity.this.textView.setText("手机桌面背景修改Error");
                    }
                    return false;
                }
            });
    
        }
    
    
        @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;
        }
        
    }
  • 相关阅读:
    vue使用百度地图
    Genymotion模拟器使用camera
    angular集成tinymce
    react-native环境搭建
    linux系统下安装ssl证书(tomcat)
    vue图片上传及java存储图片(亲测可用)
    那些年vue踩过的坑
    垃圾分类装置仿真实训
    《报任安书》文言文化常识闯关游戏·网络版
    《报任安书》文言文化常识闯关游戏
  • 原文地址:https://www.cnblogs.com/alamps/p/5248553.html
Copyright © 2011-2022 走看看