最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)手機(jī)壁紙改變的方法

 更新時(shí)間:2015年09月26日 12:18:12   作者:Ruthless  
這篇文章主要介紹了Android實(shí)現(xiàn)手機(jī)壁紙改變的方法,以完整實(shí)例形式分析了Android手機(jī)壁紙改變的方法,包括頁面布局及屬性設(shè)置的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Android實(shí)現(xiàn)手機(jī)壁紙改變的方法。分享給大家供大家參考。具體如下:

main.xml布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <Button android:id="@+id/clearWall"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:text="恢復(fù)默認(rèn)墻紙" />
  <ImageView android:id="@+id/currWall" 
    android:layout_width="100px"
    android:layout_height="150px"
    android:layout_gravity="center_horizontal" />
  <Button android:id="@+id/getWall" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:text="獲取當(dāng)前墻紙" />
  <Gallery android:id="@+id/gallery"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
  <Button android:id="@+id/setWall" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:text="設(shè)置為當(dāng)前墻紙" />
</LinearLayout>

清單文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.ljq.activity"
   android:versionCode="1"
   android:versionName="1.0">
  <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".WallActivity"
         android:label="@string/app_name">
      <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" />
  <!-- 設(shè)置手機(jī)墻紙權(quán)限 -->
  <uses-permission android:name="android.permission.SET_WALLPAPER" />
</manifest>

WallAdapter自定義適配器:

package com.ljq.activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class WallAdapter extends BaseAdapter {
  private int[] imgIds = null;
  private Context context = null;
  public WallAdapter(int[] imgIds, Context context) {
    super();
    this.imgIds = imgIds;
    this.context = context;
  }
  public int getCount() {
    return imgIds.length;
  }
  public Object getItem(int position) {
    //return imgIds[position];
    return imgIds[position%imgIds.length];//可循環(huán)
  }
  public long getItemId(int position) {
    return position;
  }
  public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(context);
    imageView.setBackgroundResource(imgIds[position]);// 設(shè)置ImageView的背景圖片
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new Gallery.LayoutParams(120, 120));
    return imageView;
  }
}

WallActivity類:

package com.ljq.activity;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemSelectedListener;
public class WallActivity extends Activity {
  private int[] imgIds={R.drawable.w1, R.drawable.w2, R.drawable.w3, R.drawable.w4};
  private int selectIndex=-1;//被選中的圖片在id數(shù)組中的索引
  private ImageView currWall=null;
  private Gallery gallery=null;
  private Button clearWall=null;
  private Button getWall=null;
  private Button setWall=null;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    gallery=(Gallery)findViewById(R.id.gallery);
    gallery.setAdapter(new WallAdapter(imgIds, WallActivity.this));
    gallery.setSpacing(5);
    gallery.setOnItemSelectedListener(new OnItemSelectedListener(){
      public void onItemSelected(AdapterView<?> parent, View view,
          int position, long id) {
        selectIndex = position;//記錄被選中的圖片索引
      }
      public void onNothingSelected(AdapterView<?> parent) {
      }
    });
    currWall=(ImageView)findViewById(R.id.currWall);
    clearWall=(Button)findViewById(R.id.clearWall);
    getWall=(Button)findViewById(R.id.getWall);
    setWall=(Button)findViewById(R.id.setWall);
    clearWall.setOnClickListener(listener);
    getWall.setOnClickListener(listener);
    setWall.setOnClickListener(listener);
  }
  View.OnClickListener listener=new View.OnClickListener(){
    public void onClick(View v) {
      Button btn=(Button)v;
      switch (btn.getId()) {
      case R.id.clearWall://還原手機(jī)壁紙
        try {
          WallActivity.this.clearWallpaper();
        } catch (IOException e) {
          e.printStackTrace();
        }
        break;
      case R.id.getWall://設(shè)置ImageView顯示的內(nèi)容為當(dāng)前墻紙
        currWall.setBackgroundDrawable(getWallpaper());
        break;
      case R.id.setWall://設(shè)置墻紙
        InputStream in=WallActivity.this.getResources().openRawResource(imgIds[selectIndex]);
        try {
          setWallpaper(in);
        } catch (IOException e) {
          e.printStackTrace();
        }
        break;
      }
    }
  };
}

運(yùn)行結(jié)果:

希望本文所述對大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android列表選擇框Spinner使用方法詳解

    Android列表選擇框Spinner使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Android列表選擇框Spinner的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android開發(fā)之圖片壓縮工具類完整實(shí)例

    Android開發(fā)之圖片壓縮工具類完整實(shí)例

    這篇文章主要介紹了Android開發(fā)之圖片壓縮工具類,結(jié)合完整實(shí)例形式分析了Android針對圖片壓縮的相關(guān)屬性設(shè)置與轉(zhuǎn)換操作實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2017-11-11
  • android選擇視頻文件上傳到后臺(tái)服務(wù)器

    android選擇視頻文件上傳到后臺(tái)服務(wù)器

    這篇文章主要介紹了android選擇視頻文件上傳到后臺(tái)服務(wù)器的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Android手機(jī)衛(wèi)士之設(shè)置密碼對話框

    Android手機(jī)衛(wèi)士之設(shè)置密碼對話框

    這篇文章主要為大家詳細(xì)介紹了Android手機(jī)衛(wèi)士之設(shè)置密碼對話框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Android webview實(shí)現(xiàn)拍照的方法

    Android webview實(shí)現(xiàn)拍照的方法

    這篇文章主要介紹了Android webview實(shí)現(xiàn)拍照的方法的相關(guān)資料,希望通過本文能幫助到大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下
    2017-10-10
  • 代碼分析Android實(shí)現(xiàn)側(cè)滑菜單

    代碼分析Android實(shí)現(xiàn)側(cè)滑菜單

    現(xiàn)在app越來越注重用戶體驗(yàn),本文給大家分析android實(shí)現(xiàn)側(cè)滑菜單的代碼,代碼簡單易懂,感興趣的朋友一起看看吧
    2015-11-11
  • Android實(shí)現(xiàn)歡迎滑動(dòng)頁面

    Android實(shí)現(xiàn)歡迎滑動(dòng)頁面

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)歡迎滑動(dòng)頁面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android應(yīng)用開發(fā)中單元測試分析

    Android應(yīng)用開發(fā)中單元測試分析

    這篇文章主要介紹了Android應(yīng)用開發(fā)中單元測試的作用,以及何為單元測試,深入學(xué)習(xí)Android應(yīng)用開發(fā)中單元測試,需要的朋友可以參考下
    2015-12-12
  • Android自定義控件實(shí)現(xiàn)餅狀圖

    Android自定義控件實(shí)現(xiàn)餅狀圖

    這篇文章主要為大家詳細(xì)介紹了Android自定義控件實(shí)現(xiàn)餅狀圖,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • Android實(shí)現(xiàn)音樂播放器鎖屏頁

    Android實(shí)現(xiàn)音樂播放器鎖屏頁

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)音樂播放器鎖屏頁,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12

最新評論

依安县| 广元市| 牙克石市| 闵行区| 衡阳市| 合肥市| 临桂县| 洛南县| 平凉市| 新绛县| 泰和县| 兴隆县| 宜宾市| 山东| 盐亭县| 海晏县| 湛江市| 阜平县| 方正县| 平乐县| 宣城市| 武义县| 晋江市| 沂南县| 惠安县| 颍上县| 句容市| 格尔木市| 宜春市| 苏尼特右旗| 临清市| 池州市| 渝中区| 东源县| 南华县| 永福县| 静宁县| 潼关县| 高邑县| 五华县| 漯河市|