編輯:關於android開發
慕課網學習項目
android 項目 分享圖片到微信
AlertDialog 對話框設置
.9.png的編輯及使用
sdk->tools->draw9patch.bat
微信API的調用
package com.dongni.wxshare; import com.tencent.mm.sdk.modelmsg.SendMessageToWX; import com.tencent.mm.sdk.modelmsg.WXImageObject; import com.tencent.mm.sdk.modelmsg.WXMediaMessage; import com.tencent.mm.sdk.modelmsg.WXWebpageObject; import com.tencent.mm.sdk.openapi.IWXAPI; import com.tencent.mm.sdk.openapi.WXAPIFactory; import android.support.v7.app.ActionBarActivity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Typeface; import android.os.Bundle; import android.provider.MediaStore; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.*; public class MainActivity extends ActionBarActivity { private ImageView mPhoto; private EditText mWord; private Button shareBtn; private int flag=-1; private IWXAPI iwxapi; private Bitmap getPic() { shareBtn.setVisibility(View.INVISIBLE); View view =getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); return view.getDrawingCache(); } private void wxshare(int flag) { // TODO Auto-generated method stub WXWebpageObject webpage=new WXWebpageObject(); WXMediaMessage msg=new WXMediaMessage(); msg.mediaObject=new WXImageObject(getPic()); SendMessageToWX.Req req=new SendMessageToWX.Req(); req.transaction=String.valueOf(System.currentTimeMillis()); req.message=msg; req.scene=flag==0?SendMessageToWX.Req.WXSceneSession:SendMessageToWX.Req.WXSceneTimeline; //req.scene=SendMessageToWX.Req.WXSceneSession; iwxapi.sendReq(req); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉標題欄 // this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息欄 setContentView(R.layout.activity_main); iwxapi=WXAPIFactory.createWXAPI(this, "wx3507afc2c2b49ccf"); //appId iwxapi.registerApp("wx3507afc2c2b49ccf"); mPhoto=(ImageView) findViewById(R.id.pic); mWord=(EditText)findViewById(R.id.word); shareBtn=(Button)findViewById(R.id.fxbtn); mPhoto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent intent =new Intent(Intent.ACTION_PICK,null); intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); startActivityForResult(intent,100); } }); shareBtn.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub final String[] item=new String[]{"分享給好友","分享到朋友圈"}; new AlertDialog.Builder(MainActivity.this) .setTitle("分享到") //.setMessage("分享到哪?") .setItems(item, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int witch) { // TODO Auto-generated method stub flag=witch; } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub flag=-1; } }) .show(); if(flag>=0){ wxshare(flag); shareBtn.setVisibility(View.VISIBLE); } } }); mWord.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/hksn.ttf")); } @Override protected void onActivityResult(int requestCode,int resultCode,Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode==RESULT_OK&&requestCode==100){ if(data!=null){ mPhoto.setImageURI(data.getData()); } } } @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; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
Context是什麼,怎麼用,Context一.Context是什麼 官方文檔概述:關於應用程序環境的全局信息的接口。這是一個抽象類,它的實現是由安卓系統提供的。它允許訪
《循序漸進Linux》第二版即將出版發行(附封面)從《循序漸進Linux》第一版發布,到現在已經近6年了,6年的時間,技術發生了很大的變化,Linux系統的內核版本從2.
ListView中響應item的點擊事件並且刷新界面,listviewitem---恢復內容開始--- 最近在在實現listview功能中遇到了這個問題: 點擊事件寫在了
重寫MPAndroidChart顯示標記 MPAndroidChart是實現圖表功能的優秀控件, 可以完成大多數繪制需求. 對於修改第三方庫而言, 優秀的架構是繼承開發,