這篇文章主要介紹了android怎樣實現APP中改變頭像圖片,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
成都創(chuàng)新互聯2013年開創(chuàng)至今,先為玉泉街道等服務建站,玉泉街道等地企業(yè),進行企業(yè)商務咨詢服務。為玉泉街道企業(yè)網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。
具體代碼如下所示:
package com.example.studyapplication.fragment;import android.app.Activity;import android.app.AlertDialog;import android.content.Context;import android.content.Intent;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.PorterDuff;import android.graphics.PorterDuffXfermode;import android.graphics.drawable.BitmapDrawable;import android.graphics.drawable.Drawable;import android.net.Uri;import android.os.Bundle;import android.os.Environment;import android.provider.MediaStore;import android.support.annotation.Nullable;import android.support.v4.app.Fragment;import android.text.Spannable;import android.text.SpannableString;import android.text.Spanned;import android.text.method.LinkMovementMethod;import android.text.style.ForegroundColorSpan;import android.text.style.URLSpan;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.Button;import android.widget.ImageButton;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.TextView;import com.example.studyapplication.MainActivity;import com.example.studyapplication.R;import com.example.studyapplication.wode_Activity;import com.example.studyapplication.zhubanfangActivity;import com.example.studyapplication.zhuceActivity;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.lang.ref.WeakReference;import static android.app.Activity.RESULT_OK;public class WodeFragment extends Fragment implements View.OnClickListener { private View mView; private Context mAvtivity; Button youhuiquan; Button shoucang; Button guanzhu; ImageView shezhi; ImageView xiaoxi; TextView qiehuanweizhuban; static TextView denglu; LinearLayout daifukuan; LinearLayout daicanyu; LinearLayout tuikuan; LinearLayout yiwancheng; LinearLayout qingxiandenglu; LinearLayout log; LinearLayout quanbudingdan; private Button LL01,LL02,LL03; private Context mContext; private ImageButton touxiang; private Bitmap head;// 頭像Bitmap private static String path = "/sdcard/myHead/";// sd路徑 Activity mActivity; Uri uritempFile; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mView = inflater.inflate(R.layout.wode_layout, null); mActivity=this.getActivity(); //設置布局文件5888 return mView; } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.mContext = getActivity(); } /* 點擊頭像進行更換頭像 */ touxiang.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { switch (v.getId()) { case R.id.touxiang:// 更換頭像 showTypeDialog(); break; } } }); } private void initView() { LL01=(Button)getActivity().findViewById(R.id.youhuiquan); LL02=(Button) getActivity().findViewById(R.id.shoucang); LL03=(Button)getActivity().findViewById(R.id.guanzhu); touxiang = (ImageButton)getActivity().findViewById(R.id.touxiang); Bitmap bt = BitmapFactory.decodeFile(path + "log.png");// 從SD卡中找頭像,轉換成Bitmap if (bt != null) { @SuppressWarnings("deprecation") Drawable drawable = new BitmapDrawable(bt);// 轉換成drawable touxiang.setImageDrawable(drawable); } else { /** * 如果SD里面沒有則需要從
感謝你能夠認真閱讀完這篇文章,希望小編分享的“android怎樣實現APP中改變頭像圖片”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯,關注創(chuàng)新互聯行業(yè)資訊頻道,更多相關知識等著你來學習!