要导入的架包
umeng-common-1.5.0.jar
umeng-debug-1.0.0.jar
umeng-share-core-6.9.0.jar
umeng-share-QQ-simplify-6.9.0.jar
umeng-share-wechat-simplify-6.9.0.jar
umeng-share-sina-simplify-6.9.0.jar
umeng-shareboard-widget-6.9.0.jar
umeng-sharetool-6.9.0.jar
布局图
友盟布局 分包
架包
![](https://img-blog.csdn.net/20180405170544357)
清单文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.com.a">
<!-- 必须的权限 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- 推荐的权限 -->
<!-- 添加如下权限,以便使用更多的第三方SDK和更精准的统计数据 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".MyApplication"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Welcom_Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Data_MainActivity" />
<activity android:name=".Login_Activity" />
<activity android:name=".Web_Activity" />
<meta-data android:name="UMENG_APPKEY" android:value="5aaf6a54f29d984ca4000148" /> <activity android:name=".wxapi.WXEntryActivity"></activity> <!-- //新浪--> <activity android:name="com.umeng.socialize.media.WBShareCallBackActivity" android:configChanges="keyboardHidden|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:exported="false" android:screenOrientation="portrait" > </activity> <activity android:name="com.sina.weibo.sdk.web.WeiboSdkWebActivity" android:configChanges="keyboardHidden|orientation" android:exported="false" android:windowSoftInputMode="adjustResize" > </activity> <activity android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" android:launchMode="singleTask" android:name="com.sina.weibo.sdk.share.WbShareTransActivity"> <intent-filter> <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <!--qq--> <activity android:name="com.tencent.tauth.AuthActivity" android:launchMode="singleTask" android:noHistory="true" > <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="tencent100424468" /> </intent-filter> </activity> <activity android:name="com.tencent.connect.common.AssistActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="orientation|keyboardHidden|screenSize"/> <activity android:name="com.umeng.socialize.editorpage.ShareActivity" android:theme="@android:style/Theme.NoTitleBar" android:excludeFromRecents="true" />
Utils(OkHttp)
public class OkhtttpUtils { //单例模式,把构造方法进行私有化 // private OkhtttpUtils(){}; static OkHttpClient client; public static OkHttpClient getInstance(){ if (client==null) { //更加安全 synchronized (OkhtttpUtils.class) { //缓存的地方 mnt/sdcard File file = new File(Environment.getExternalStorageDirectory(), "cache11"); client = new OkHttpClient().newBuilder() .readTimeout(3000, TimeUnit.SECONDS) //设置读取超时时间 .connectTimeout(3000, TimeUnit.SECONDS) //设置连接的超时时间 .cache(new Cache(file, 10 * 1024)) .build(); } } return client; } /** * get请求 * Callback 是一个接口 */ public static void doGet(String url, Callback callback){ //1:拿到okhttpclient 对像 OkHttpClient client = getInstance(); //2:进行请求的操作 Request request = new Request.Builder() .url(url) .build(); client.newCall(request).enqueue(callback); } //post请求 /** * * @param url 请求的地址 * @param parms 请求的参数 * @param callback callback */ public static void doPost(String url, Map<String,String> parms,Callback callback){ //得到客户端的对像 OkHttpClient client = getInstance(); //不是FormBody,而是一个Builder FormBody.Builder body = new FormBody.Builder(); //key value for (String key:parms.keySet()){ //value的值 body.add(key,parms.get(key)); } Request request = new Request.Builder() .url(url) .post(body.build()) .build(); client.newCall(request).enqueue(callback); } //用来上传图片的 //url , 图片 ,参数 Callback public static void upImage(String url,File file,String filenName,Map<String,String> params,Callback callback){ OkHttpClient client = getInstance(); //requestBody的实现类 Formbody MultipartBody.Builder builder = new MultipartBody.Builder(); if (params!=null){ for (String key :params.keySet()){ builder.addFormDataPart(key,params.get(key)); } } //设置类型 builder.setType(MultipartBody.FORM); builder.addFormDataPart("file",filenName,RequestBody.create(MediaType.parse("application/octet-stream"),file)); // builder.setType(MultipartBody.FORM); // builder.addFormDataPart("file",filenName,RequestBody.create(MediaType.parse("application/octet-stream"),file)); //builder.addFormDataPart("file","aa.png",builder.build()); Request request = new Request.Builder() .url(url) .post(builder.build()) .build(); client.newCall(request).enqueue(callback); } }MyApplication类
public class MyApplication extends Application{ //三方的key { PlatformConfig.setWeixin("wx967daebe835fbeac","5bb696d9ccd75a38c8a0bfe0675559b3"); PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba"); PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad","http://sns.whalecloud.com"); } @Override public void onCreate() { super.onCreate(); // UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE, "1fe6a20054bcef865eeb0991ee84525b"); UMConfigure.init(this,"5a12384aa40fa3551f0001d1" ,"umeng",UMConfigure.DEVICE_TYPE_PHONE,"");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0 //UMShareAPI.get(this); } }
DataMoudle接口
public interface DataMoudle { void getData(String url,Presenter presenter); }
DataMoudle实现类
public class MyDataMoudle implements DataMoudle{ @Override public void getData(String url, final Presenter presenter) { //调用工具类请求数据方法 OkhtttpUtils.doGet(url, new Callback() { @Override public void onFailure(Call call, IOException e) { } //请求成功时 @Override public void onResponse(Call call, Response response) throws IOException { //得到响应内容 String string = response.body().string(); //解析 Gson gson=new Gson(); JavaBean javaBean = gson.fromJson(string, JavaBean.class); List<JavaBean.NewslistBean> list = javaBean.getNewslist(); //把请求到的list传给p层的成功方法 presenter.success(list); } }); } }
Presenter接口
public interface Presenter { void success(List<JavaBean.NewslistBean> list); void error(); }
Presenter接口实现类
public class MyPresenter implements Presenter{ private final DataView dataView; private final MyDataMoudle myDataMoudle; //提供p层构造方法 public MyPresenter(DataView dataView){ this.dataView=dataView; //创建出m层对象 myDataMoudle = new MyDataMoudle(); } @Override public void success(List<JavaBean.NewslistBean> list) { //把解析到的list传给v层 dataView.getZdata(list); } @Override public void error() { } //定义 得到v层传来的url 调用m层请求数据方法得到请求数据 传给v 参数是url public void getmData(String url){ myDataMoudle.getData(url,this); }; }
DataView接口
public interface DataView { void getZdata(List<JavaBean.NewslistBean> list); }
DataView接口实现类
public class Data_MainActivity extends AppCompatActivity implements DataView,MyAdapter.SetClick{ private String url="http://api.tianapi.com/startup/?key=71e58b5b2f930eaf1f937407acde08fe&num=10"; private RecyclerView re_view; private MyAdapter adapter; private List<JavaBean.NewslistBean> list; private Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); list = (List<JavaBean.NewslistBean>) msg.obj; //得到控制器 LinearLayoutManager manager=new LinearLayoutManager(Data_MainActivity.this); //把re_view布局和控制器绑定 re_view.setLayoutManager(manager); //为re_view设置适配器 adapter = new MyAdapter(Data_MainActivity.this, list); re_view.setAdapter(adapter); //通过得到接口对象方法把自己作为接口对象传给接口 adapter.getInterface(Data_MainActivity.this); } } ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //找到控件 re_view = findViewById(R.id.re_view); //创建p层对象 MyPresenter presenter=new MyPresenter(this); presenter.getmData(url); } @Override public void getZdata(List<JavaBean.NewslistBean> list) { //创建消息对象 Message message=new Message(); message.obj=list; handler.sendMessage(message); } //条目点击事件 @Override public void itemClick(int i) { Intent intent=new Intent(Data_MainActivity.this,Web_Activity.class); //得到子url存到intent中 String weburl = list.get(i).getUrl(); intent.putExtra("url",weburl); startActivity(intent);//跳转 } @Override public void longClick(int i) { list.remove(i);//删除子条目 adapter.notifyDataSetChanged();//刷新适配器 } }
欢迎页面(属性动画)Welcom_Activity
public class Welcom_Activity extends AppCompatActivity { private ImageView fan; private ImageView zheng; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcom_); //找到控件 fan = findViewById(R.id.img_f); zheng = findViewById(R.id.img_z); ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(fan, "rotationY", 0,90); objectAnimator.setDuration(3000); objectAnimator.start(); objectAnimator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } //动画结束 @Override public void onAnimationEnd(Animator animator) { fan.setVisibility(View.INVISIBLE);//隐藏 zheng.setVisibility(View.VISIBLE);//显示 Intent intent=new Intent(Welcom_Activity.this,Login_Activity.class); startActivity(intent); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); } }
动画布局activity_welcom_.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/z" android:id="@+id/img_z" android:visibility="invisible" /> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/f" android:id="@+id/img_f" /> </FrameLayout>
登录布局activity_login_.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第三方登录" android:gravity="center_horizontal" android:padding="10dp" android:id="@+id/top_text" android:background="#C3DADB" /> <ImageView android:layout_width="50dp" android:layout_height="50dp" android:src="@drawable/mqq" android:layout_centerHorizontal="true" android:layout_below="@+id/top_text" android:id="@+id/qq_img" android:layout_marginTop="20dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="QQ登录" android:layout_centerHorizontal="true" android:layout_below="@+id/qq_img" android:id="@+id/qq" android:layout_marginTop="10dp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_below="@+id/qq" android:id="@+id/show_data" android:visibility="invisible" android:gravity="center_horizontal"> <ImageView android:layout_width="100dp" android:layout_height="100dp" android:src="@mipmap/ic_launcher" android:layout_gravity="center" android:layout_marginTop="20dp" android:id="@+id/tou_img"/> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="昵称:" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1111" android:textColor="#f0f" android:id="@+id/t_name" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性别:" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1111" android:textColor="#f0f" android:id="@+id/t_sex" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="地址:" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1111" android:id="@+id/t_adress" android:textColor="#f0f" /> </LinearLayout> </LinearLayout> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="跳过" android:background="#C3DADB" android:id="@+id/tiao"/> </RelativeLayout>
登录类Login_Activity
public class Login_Activity extends AppCompatActivity { private ImageView qq_img; private ImageView tou_img; private TextView name; private TextView sex; private TextView adress; private TextView time; private Button tiao; private LinearLayout show_data; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login_); //找到控件 show_data = findViewById(R.id.show_data); qq_img = findViewById(R.id.qq_img); tou_img = findViewById(R.id.tou_img); name = findViewById(R.id.t_name); sex = findViewById(R.id.t_sex); adress = findViewById(R.id.t_adress); tiao = findViewById(R.id.tiao); //为跳转按钮设置监听事件 tiao.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent=new Intent(Login_Activity.this,Data_MainActivity.class); startActivity(intent); } }); //为qq_img按钮设置监听 qq_img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //做登录的操作 UMAuthListener authListener = new UMAuthListener() { /** * @desc 授权开始的回调 * @param platform 平台名称 */ @Override public void onStart(SHARE_MEDIA platform) { } /** * @desc 授权成功的回调 * @param platform 平台名称 * @param action 行为序号,开发者用不上 * @param data 用户资料返回 */ @Override public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) { Log.d("---", "onComplete: "+data); String image= data.get("iconurl"); String t_city = data.get("city"); String province = data.get("province"); String t_name = data.get("name"); String t_sex = data.get("gender"); if(data != null){ //赋值 Glide.with(Login_Activity.this).load(image).into(tou_img); adress.setText(province+"省"+t_city+"市"); name.setText(t_name); sex.setText(t_sex); //布局显示 show_data.setVisibility(View.VISIBLE); }else{ show_data.setVisibility(View.INVISIBLE); } } /** * @desc 授权失败的回调 * @param platform 平台名称 * @param action 行为序号,开发者用不上 * @param t 错误原因 */ @Override public void onError(SHARE_MEDIA platform, int action, Throwable t) { Toast.makeText(Login_Activity.this, "失败:" + t.getMessage(), Toast.LENGTH_LONG).show(); } /** * @desc 授权取消的回调 * @param platform 平台名称 * @param action 行为序号,开发者用不上 */ @Override public void onCancel(SHARE_MEDIA platform, int action) { Toast.makeText(Login_Activity.this, "取消了", Toast.LENGTH_LONG).show(); } }; UMShareAPI umShareAPI = UMShareAPI.get(Login_Activity.this); umShareAPI.getPlatformInfo(Login_Activity.this, SHARE_MEDIA.QQ, authListener); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); UMShareAPI.get(this).onActivityResult(requestCode,resultCode,data); } }
Data_MainActivity主页面
public class Data_MainActivity extends AppCompatActivity implements DataView,MyAdapter.SetClick{ private String url="http://api.tianapi.com/startup/?key=71e58b5b2f930eaf1f937407acde08fe&num=10"; private RecyclerView re_view; private MyAdapter adapter; private List<JavaBean.NewslistBean> list; private Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); list = (List<JavaBean.NewslistBean>) msg.obj; //得到控制器 LinearLayoutManager manager=new LinearLayoutManager(Data_MainActivity.this); //把re_view布局和控制器绑定 re_view.setLayoutManager(manager); //为re_view设置适配器 adapter = new MyAdapter(Data_MainActivity.this, list); re_view.setAdapter(adapter); //通过得到接口对象方法把自己作为接口对象传给接口 adapter.getInterface(Data_MainActivity.this); } } ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //找到控件 re_view = findViewById(R.id.re_view); //创建p层对象 MyPresenter presenter=new MyPresenter(this); presenter.getmData(url); } @Override public void getZdata(List<JavaBean.NewslistBean> list) { //创建消息对象 Message message=new Message(); message.obj=list; handler.sendMessage(message); } //条目点击事件 @Override public void itemClick(int i) { Intent intent=new Intent(Data_MainActivity.this,Web_Activity.class); //得到子url存到intent中 String weburl = list.get(i).getUrl(); intent.putExtra("url",weburl); startActivity(intent);//跳转 } @Override public void longClick(int i) { list.remove(i);//删除子条目 adapter.notifyDataSetChanged();//刷新适配器 } }MyAdapter类
public class MyAdapter extends RecyclerView.Adapter{ Context context; List<JavaBean.NewslistBean> list; private MyviewHolder myviewHolder; private SetClick setClick; public MyAdapter(Context context, List<JavaBean.NewslistBean> list) { this.context=context; this.list=list; } //定义得到接口对象的方法 public void getInterface(SetClick setClick){ this.setClick=setClick; } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { //引入布局 View view=View.inflate(context, R.layout.ietm_layout,null); //把布局和viewholder绑定 myviewHolder = new MyviewHolder(view); return myviewHolder; } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) { //把自定义myviewHolder和自带holder绑定 myviewHolder= (MyviewHolder) holder; //赋值,先得到图片 String picUrl = list.get(position).getPicUrl(); Glide.with(context).load(picUrl).into(myviewHolder.re_img1); myviewHolder.re_title1.setText(list.get(position).getTitle()); myviewHolder.re_time1.setText(list.get(position).getCtime()); //为条目设置监听 myviewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //调用接口中定义的条目点击事件 setClick.itemClick(position); } }); //为条目设置长按监听 myviewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { setClick.longClick(position); return false; } }); } @Override public int getItemCount() { return list.size(); } //创建viewholder class MyviewHolder extends RecyclerView.ViewHolder{ private final ImageView re_img1; private final TextView re_title1; private final TextView re_time1; public MyviewHolder(View itemView) { super(itemView); //找到控件 re_img1 = itemView.findViewById(R.id.re_img); re_title1 = itemView.findViewById(R.id.re_title); re_time1 = itemView.findViewById(R.id.re_time); } } //定义接口 public interface SetClick{ //定义条目点击事件 void itemClick(int i); //定义长按点击事件 void longClick(int i); } }
Data_MainActivity布局<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.com.a.view.Data_MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="标题" android:padding="10dp" android:gravity="center_horizontal" android:background="#C3DADB"/> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/re_view"></android.support.v7.widget.RecyclerView> </LinearLayout>
webView页面布局
<?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"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#C3DADB" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="详情" android:gravity="center_horizontal" android:layout_weight="1" android:id="@+id/xiangq"/> <Button android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="分享" android:background="#C3DADB" android:id="@+id/fenx" android:layout_alignParentRight="true"/> </LinearLayout> <WebView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/web" ></WebView> </LinearLayout>
Web_Activity类
public class Web_Activity extends AppCompatActivity { private WebView web; private Button fenx; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web_); //找到控件 web = findViewById(R.id.web); fenx = findViewById(R.id.fenx); //得到intent Intent intent = getIntent(); String url = intent.getStringExtra("url"); web.loadUrl(url); WebSettings settings = web.getSettings();//设置 settings.setJavaScriptEnabled(true);//设置支持javascript //支持缩放 settings.setSupportZoom(true); web.setWebViewClient(new WebViewClient());// /* * 分享 * */ fenx.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { UMWeb web = new UMWeb("http//:www.baidu.com"); web.setTitle("我是分享的页面");//标题 web.setDescription("my description");//描述 new ShareAction(Web_Activity.this).withMedia(web).setDisplayList(SHARE_MEDIA.SINA,SHARE_MEDIA.QQ,SHARE_MEDIA.WEIXIN) .setCallback(shareListener).open(); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); UMShareAPI.get(this).onActivityResult(requestCode,resultCode,data); } private UMShareListener shareListener = new UMShareListener() { /** * @descrption 分享开始的回调 * @param platform 平台类型 */ @Override public void onStart(SHARE_MEDIA platform) { } /** * @descrption 分享成功的回调 * @param platform 平台类型 */ @Override public void onResult(SHARE_MEDIA platform) { Toast.makeText(Web_Activity.this,"成功了",Toast.LENGTH_LONG).show(); } /** * @descrption 分享失败的回调 * @param platform 平台类型 * @param t 错误原因 */ @Override public void onError(SHARE_MEDIA platform, Throwable t) { Toast.makeText(Web_Activity.this,"失败"+t.getMessage(),Toast.LENGTH_LONG).show(); } /** * @descrption 分享取消的回调 * @param platform 平台类型 */ @Override public void onCancel(SHARE_MEDIA platform) { Toast.makeText(Web_Activity.this,"取消了",Toast.LENGTH_LONG).show(); } }; }
微信分享所需类
public class WXEntryActivity extends WXCallbackActivity { }
RecyclerView子布局item
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <ImageView android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/re_img" android:src="@mipmap/ic_launcher" android:layout_marginTop="20dp" android:layout_marginLeft="20dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/re_title" android:text="111" android:layout_marginTop="20dp" android:layout_marginLeft="40dp" android:layout_toRightOf="@+id/re_img"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/re_time" android:text="111" android:layout_marginTop="40dp" android:layout_marginLeft="40dp" android:layout_toRightOf="@+id/re_img" android:layout_below="@+id/re_title"/> </RelativeLayout>
友盟布局
socialize_share_menu_item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical"> <com.umeng.socialize.shareboard.SocializeImageView android:id="@+id/socialize_image_view" android:layout_width="50dp" android:layout_height="50dp" android:padding="5dp" android:src="@drawable/umeng_socialize_menu_default" /> <TextView android:id="@+id/socialize_text_view" android:layout_width="63dp" android:layout_height="wrap_content" android:layout_marginTop="6dp" android:ellipsize="end" android:singleLine="true" android:text="未知" android:textSize="12sp" /> </LinearLayout>
umeng_socialize_oauth_dialog.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#D4E0E5"> <RelativeLayout android:id="@+id/umeng_socialize_titlebar" android:layout_width="match_parent" android:layout_height="54dp" android:background="#0086DC"> <TextView android:id="@+id/umeng_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="" android:textColor="#ffffff" android:textSize="18sp" /> <RelativeLayout android:id="@+id/umeng_back" android:layout_width="60dp" android:layout_height="match_parent" android:onClick="onCancel" android:visibility="visible"> <ImageButton android:layout_width="12dp" android:layout_height="20dp" android:layout_centerVertical="true" android:background="@drawable/umeng_socialize_back_icon" android:layout_marginLeft="15dp" android:scaleType="center" /> </RelativeLayout> <TextView android:id="@+id/umeng_share_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerInParent="true" android:layout_marginRight="10dp" android:background="@drawable/umeng_socialize_btn_bg" android:padding="4dp" android:text="分享" android:textColor="#ffffff" /> </RelativeLayout> <RelativeLayout android:id="@+id/umeng_socialize_follow" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_alignParentBottom="true" android:background="#AAAAAA" android:visibility="visible"> <CheckBox android:id="@+id/umeng_socialize_follow_check" android:layout_width="20dp" android:layout_height="20dp" android:layout_centerVertical="true" android:layout_marginLeft="20dp" android:checked="true" android:visibility="gone" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@id/umeng_socialize_follow_check" android:text="关注官方微博" android:textColor="#f8f8f8" android:textSize="16sp" android:visibility="gone" /> </RelativeLayout> <WebView android:id="@+id/webView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#F2F5F6" android:layout_above="@id/umeng_socialize_follow" android:layout_below="@id/umeng_socialize_titlebar" android:visibility="visible" /> <RelativeLayout android:id="@+id/progress_bar_parent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/umeng_socialize_titlebar" android:background="#F2F5F6" > <LinearLayout android:layout_width="80dp" android:layout_height="80dp" android:layout_centerInParent="true" android:orientation="horizontal"> <ProgressBar android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="10dp" /> </LinearLayout> </RelativeLayout> </RelativeLayout>
umeng_socialize_share.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#D4E0E5" android:id="@+id/root" android:orientation="vertical"> <RelativeLayout android:id="@+id/umeng_socialize_share_titlebar" android:layout_width="match_parent" android:layout_height="54dp" android:background="#0086DC"> <TextView android:id="@+id/umeng_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="" android:textColor="#ffffff" android:textSize="18sp" /> <RelativeLayout android:id="@+id/umeng_back" android:layout_width="50dp" android:layout_height="match_parent" android:onClick="onCancel" android:visibility="visible"> <ImageButton android:layout_width="12dp" android:layout_height="20dp" android:layout_centerVertical="true" android:layout_marginLeft="15dp" android:background="@drawable/umeng_socialize_back_icon" android:clickable="false" android:scaleType="center" /> </RelativeLayout> <TextView android:id="@+id/umeng_share_btn" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_centerInParent="true" android:gravity="center_vertical" android:paddingLeft="15dp" android:paddingRight="15dp" android:text="分享" android:textColor="#ffffff" android:textSize="15sp" /> </RelativeLayout> <EditText android:id="@+id/umeng_socialize_share_edittext" android:layout_width="fill_parent" android:layout_height="180dp" android:layout_below="@id/umeng_socialize_share_titlebar" android:paddingLeft="15dp" android:paddingRight="15dp" android:paddingTop="8dp" android:background="#ffffff" android:bufferType="spannable" android:gravity="top" android:hint="编辑分享内容" android:lineSpacingExtra="3dp" android:paddingBottom="10dp" android:textColor="#000000" android:textSize="15sp" /> <TextView android:id="@+id/umeng_socialize_share_word_num" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignRight="@id/umeng_socialize_share_edittext" android:background="#ffffff" android:layout_below="@id/umeng_socialize_share_edittext" android:paddingBottom="10dp" android:paddingRight="15dp" android:gravity="right" android:singleLine="true" android:textColor="#98999B" android:textSize="14sp" /> <RelativeLayout android:id="@+id/umeng_socialize_share_bottom_area" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/umeng_socialize_share_word_num" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:background="#F2F5F6" android:visibility="gone"> <RelativeLayout android:layout_width="62dp" android:layout_height="62dp" android:layout_centerVertical="true" android:layout_marginBottom="15dp" android:layout_marginLeft="15dp" android:id="@+id/umeng_image_edge" android:layout_marginTop="15dp" android:background="@drawable/umeng_socialize_edit_bg" > <ImageView android:id="@+id/umeng_share_icon" android:layout_width="60dp" android:layout_height="60dp" android:layout_centerInParent="true" android:src="#2c3035" /> </RelativeLayout> <TextView android:layout_width="280dp" android:id="@+id/umeng_web_title" android:layout_toRightOf="@id/umeng_image_edge" android:layout_marginLeft="40dp" android:layout_marginTop="20dp" android:textColor="#575A5C" android:singleLine="true" android:textSize="14sp" android:visibility="gone" android:layout_height="wrap_content" /> <ImageView android:id="@+id/umeng_del" android:layout_width="20dp" android:layout_height="20dp" android:layout_alignRight="@id/umeng_image_edge" android:layout_alignTop="@id/umeng_image_edge" android:layout_marginRight="-10dp" android:layout_marginTop="-10dp" android:background="@drawable/umeng_socialize_delete" /> </RelativeLayout></RelativeLayout>