forked from huyongli/huyongli.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Retrofit2使用介绍.html
679 lines (505 loc) · 43.1 KB
/
Retrofit2使用介绍.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
<!DOCTYPE html>
<html lang=zh>
<head>
<meta charset="utf-8">
<title>Retrofit2使用介绍 | 老胡</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="description" content="前言对于还不知道Refrofit是什么的同学,我只能说你们太out了,赶紧去Google下,本文是针对Retrofit2.0的使用介绍,当然大家也可以直接去官网上去看使用介绍
添加依赖要使用Retrofit首先得添加gradle依赖12compile &apos;com.squareup.retrofit2:retrofit:2.0.2&apos;compile &apos;com.squareu">
<meta property="og:type" content="article">
<meta property="og:title" content="Retrofit2使用介绍">
<meta property="og:url" content="http://ittiger.cn/Retrofit2使用介绍.html">
<meta property="og:site_name" content="老胡">
<meta property="og:description" content="前言对于还不知道Refrofit是什么的同学,我只能说你们太out了,赶紧去Google下,本文是针对Retrofit2.0的使用介绍,当然大家也可以直接去官网上去看使用介绍
添加依赖要使用Retrofit首先得添加gradle依赖12compile &apos;com.squareup.retrofit2:retrofit:2.0.2&apos;compile &apos;com.squareu">
<meta property="og:updated_time" content="2016-08-30T09:26:33.706Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Retrofit2使用介绍">
<meta name="twitter:description" content="前言对于还不知道Refrofit是什么的同学,我只能说你们太out了,赶紧去Google下,本文是针对Retrofit2.0的使用介绍,当然大家也可以直接去官网上去看使用介绍
添加依赖要使用Retrofit首先得添加gradle依赖12compile &apos;com.squareup.retrofit2:retrofit:2.0.2&apos;compile &apos;com.squareu">
<link rel="alternate" href="atom.xml" title="老胡" type="application/atom+xml" />
<link rel="stylesheet" href="/libs/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="/libs/open-sans/styles.css">
<link rel="stylesheet" href="/libs/source-code-pro/styles.css">
<link rel="stylesheet" href="/css/style.css">
<script src="/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="/libs/lightgallery/css/lightgallery.min.css">
<link rel="stylesheet" href="/libs/justified-gallery/justifiedGallery.min.css">
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "//hm.baidu.com/hm.js?5e886c0a11c8dce0abbe888faadd1000";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body>
<div id="container">
<header id="header">
<div id="header-main" class="header-inner">
<div class="outer">
<a href="/" id="logo">
<i class="logo"></i>
<span class="site-title">老胡</span>
</a>
<nav id="main-nav">
<a class="main-nav-link" href="/.">主页</a>
<a class="main-nav-link" href="/archives">归档</a>
<a class="main-nav-link" href="/categories">分类</a>
<a class="main-nav-link" href="/tags">标签</a>
<a class="main-nav-link" href="/about">关于</a>
<a class="main-nav-link" href="/website">干货</a>
</nav>
<nav id="sub-nav">
<div class="profile" id="profile-nav">
<a id="profile-anchor" href="javascript:;">
<img class="avatar" src="/css/images/avatar.png" />
<i class="fa fa-caret-down"></i>
</a>
</div>
</nav>
<div id="search-form-wrap">
<form class="search-form">
<input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
<button type="submit" class="search-form-submit"></button>
</form>
<div class="ins-search">
<div class="ins-search-mask"></div>
<div class="ins-search-container">
<div class="ins-input-wrapper">
<input type="text" class="ins-search-input" placeholder="想要查找什么..." />
<span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
</div>
<div class="ins-section-wrapper">
<div class="ins-section-container"></div>
</div>
</div>
</div>
<script>
(function (window) {
var INSIGHT_CONFIG = {
TRANSLATION: {
POSTS: '文章',
PAGES: '页面',
CATEGORIES: '分类',
TAGS: '标签',
UNTITLED: '(未命名)',
},
ROOT_URL: '/',
CONTENT_URL: '/content.json',
};
window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>
</div>
</div>
</div>
<div id="main-nav-mobile" class="header-sub header-inner">
<table class="menu outer">
<tr>
<td><a class="main-nav-link" href="/.">主页</a></td>
<td><a class="main-nav-link" href="/archives">归档</a></td>
<td><a class="main-nav-link" href="/categories">分类</a></td>
<td><a class="main-nav-link" href="/tags">标签</a></td>
<td><a class="main-nav-link" href="/about">关于</a></td>
<td><a class="main-nav-link" href="/website">干货</a></td>
<td>
<div class="search-form">
<input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
</div>
</td>
</tr>
</table>
</div>
</header>
<div class="outer">
<aside id="profile">
<div class="inner profile-inner">
<div class="base-info profile-block">
<img id="avatar" src="/css/images/avatar.png" />
<h2 id="name">老胡</h2>
<h3 id="title">Android Developer</h3>
<span id="location"><i class="fa fa-map-marker"></i>WuHan, China</span>
<a id="follow" target="_blank" href="https://github.com/huyongli/">关注我</a>
</div>
<div class="article-info profile-block">
<div class="article-info-block">
49
<span>文章</span>
</div>
<div class="article-info-block">
47
<span>标签</span>
</div>
</div>
<div class="profile-block social-links">
<table>
<tr>
<td>
<a href="http://github.com/huyongli" target="_blank" title="github" class=tooltip>
<i class="fa fa-github"></i>
</a>
</td>
<td>
<a href="http://weibo.com/aclaohu" target="_blank" title="weibo" class=tooltip>
<i class="fa fa-weibo"></i>
</a>
</td>
<td>
<a href="/atom.xml" target="_blank" title="rss" class=tooltip>
<i class="fa fa-rss"></i>
</a>
</td>
</tr>
</table>
</div>
</div>
</aside>
<section id="main"><article id="post-Retrofit2使用介绍" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 class="article-title" itemprop="name">
Retrofit2使用介绍
</h1>
<div class="article-meta">
<div class="article-date">
<i class="fa fa-calendar"></i>
<a href="/Retrofit2使用介绍.html">
<time datetime="2016-08-29T12:50:13.000Z" itemprop="datePublished">2016-08-29</time>
</a>
</div>
<div class="article-category">
<i class="fa fa-folder"></i>
<a class="article-category-link" href="/categories/Android/">Android</a>
</div>
<div class="article-tag">
<i class="fa fa-tag"></i>
<a class="tag-link" href="/tags/Android/">Android</a>, <a class="tag-link" href="/tags/Retrofit/">Retrofit</a>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<h4 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h4><p>对于还不知道Refrofit是什么的同学,我只能说你们太out了,赶紧去Google下,本文是针对Retrofit2.0的使用介绍,当然大家也可以直接去<a href="http://square.github.io/retrofit/" target="_blank" rel="external">官网</a>上去看使用介绍</p>
<h4 id="添加依赖"><a href="#添加依赖" class="headerlink" title="添加依赖"></a>添加依赖</h4><p>要使用Retrofit首先得添加gradle依赖<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">compile 'com.squareup.retrofit2:retrofit:2.0.2'</div><div class="line">compile 'com.squareup.retrofit2:converter-gson:2.0.0'</div></pre></td></tr></table></figure></p>
<h4 id="声明服务接口"><a href="#声明服务接口" class="headerlink" title="声明服务接口"></a>声明服务接口</h4><p>依赖添加完成之后,就可以开始撸代码了,首先我们要新建一个Interface,这个接口就是你要请求的接口服务类,就像这个样子</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">RetrofitService</span> </span>{</div><div class="line"></div><div class="line"> <span class="meta">@GET</span>(<span class="string">"getModelService"</span>)</div><div class="line"> <span class="function">Call<User> <span class="title">getModelService</span><span class="params">()</span></span>;</div><div class="line"> ...</div><div class="line">}</div></pre></td></tr></table></figure>
<p>上面这个接口中暂时只声明了一个方法,而在Retrofit中想这样声明的一个方法就代表了一个具体的Http请求接口。Retrofit中方法上添加<code>@GET</code>注解就表示当前方法代表一个Get请求,我们声明的这个请求方法不带任何参数,且返回结果是User对象。<br><code>@GET</code>注解括号中的值<code>getModelService</code>就代表http请求地址的具体指向,这个值与下面baseUrl中配置的URL一起组成一个完整的请求地址<br>Retrofit就是这么任性,它可以帮我们把http的请求结果自动转换成Javabean对象,这将为我们减少不少编码工作。</p>
<h4 id="构造Retrofit对象"><a href="#构造Retrofit对象" class="headerlink" title="构造Retrofit对象"></a>构造Retrofit对象</h4><p>接口服务声明完成之后,我们接着需要新建一个Retrofit对象<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">Retrofit retrofit = <span class="keyword">new</span> Retrofit.Builder()</div><div class="line"> .baseUrl(<span class="string">"http://localhost:8080/AndroidService/"</span>)</div><div class="line"> .addConverterFactory(GsonConverterFactory.create())</div><div class="line"> .build();</div><div class="line">RetrofitService service = retrofit.create(RetrofitService.class);</div></pre></td></tr></table></figure></p>
<a id="more"></a>
<p>通过上面的代码我们就创建了一个Retrofit对象,同时通过这个Retrofit对象将我们前面声明的服务接口进行了实例化,有了这个服务接口实例化对象,我们就可以调用接口里面声明的方法进行http请求了。</p>
<ol>
<li>另外需要说明是我们在设置baseUrl的时候一般在都是以/结尾,而不是在接口方法中的url以/开头</li>
<li>前面说的Retrofit会将请求结果自动转换成Javabean对象,其实这个是需要配置结果转换器的,就像上面我配置的<code>addConverterFactory(GsonConverterFactory.create())</code>,配置了这个转换器工厂之后,就会将请求得到的JSON数据自动转换成Javabean对象。同样如果请求得到的数据是xml类型的话,转换成Javabean对象则需要配置成其他类型的转换器</li>
<li>Retrofit其实已经为我们提供了多种转换器供我们选择:<blockquote>
<p>Gson: com.squareup.retrofit2:converter-gson<br>Jackson: com.squareup.retrofit2:converter-jackson<br>Moshi: com.squareup.retrofit2:converter-moshi<br>Protobuf: com.squareup.retrofit2:converter-protobuf<br>Wire: com.squareup.retrofit2:converter-wire<br>Simple XML: com.squareup.retrofit2:converter-simplexml<br>Scalars (primitives, boxed, and String): com.squareup.retrofit2:converter-scalars</p>
</blockquote>
</li>
</ol>
<h4 id="同步请求"><a href="#同步请求" class="headerlink" title="同步请求"></a>同步请求</h4><p>前面准备工作都完成了,ok,可以开始发起请求了<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">Call<User> call = service.getModelServiceSync();</div><div class="line">Response<User> response = call.execute();</div><div class="line"><span class="keyword">if</span>(response.isSuccessful()) {</div><div class="line"> User user = response.body();</div><div class="line">}</div></pre></td></tr></table></figure></p>
<p>这就是Retrofit的基本使用流程:添加依赖–>声明接口–>创建Retrofit和接口对象–>选择执行同步异步请求</p>
<h4 id="异步请求"><a href="#异步请求" class="headerlink" title="异步请求"></a>异步请求</h4><p>同步请求执行<code>call.execute()</code>即可,异步请求则是这样:<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">call.enqueue(<span class="keyword">new</span> Callback<User>() {</div><div class="line"> <span class="meta">@Override</span></div><div class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onResponse</span><span class="params">(Call<User> call, Response<User> response)</span> </span>{</div><div class="line"> <span class="keyword">if</span>(response.isSuccessful()) {</div><div class="line"> User user = response.body();</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="meta">@Override</span></div><div class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onFailure</span><span class="params">(Call<User> call, Throwable t)</span> </span>{</div><div class="line"></div><div class="line"> }</div><div class="line">});</div></pre></td></tr></table></figure></p>
<h4 id="带参Get请求"><a href="#带参Get请求" class="headerlink" title="带参Get请求"></a>带参Get请求</h4><p>如果要实现带参数的Get请求,则需要将我们上面的方法声明改成如下形式<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@GET</span>(<span class="string">"getModelService"</span>)</div><div class="line"><span class="function">Call<User> <span class="title">getModelService</span><span class="params">(@Query(<span class="string">"param1"</span>)</span> <span class="keyword">boolean</span> param1, @<span class="title">Query</span><span class="params">(<span class="string">"param2"</span>)</span> <span class="keyword">boolean</span> param2)</span>;</div></pre></td></tr></table></figure></p>
<p>Retrofit中我们只需要将要传输到服务端的参数添加<code>@Query</code>注解即可,而<code>@Query</code>注解括号中的值<code>param1</code>和<code>param2</code>则是对应的参数名</p>
<p>Retrofit也为我们提供了另外一种形式,使用<code>@QueryMap</code>注解来声明一个集合作为请求参数<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@GET</span>(<span class="string">"getModelService"</span>)</div><div class="line"><span class="function">Call<User> <span class="title">getModelService</span><span class="params">(@QueryMap Map<String, String> parmas)</span></span>;</div></pre></td></tr></table></figure></p>
<h4 id="动态URL"><a href="#动态URL" class="headerlink" title="动态URL"></a>动态URL</h4><p>如果我们有两个这样的请求地址<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">http:<span class="comment">//localhost:8080/AndroidService/user/zhangsan</span></div><div class="line">http:<span class="comment">//localhost:8080/AndroidService/user/lisi</span></div></pre></td></tr></table></figure></p>
<p>这两个请求地址很明显,除了最后的一段不一样其他的都一样。因此如果按照上面的做法的话,我们要请求这两个服务就需要声明两个接口方法,如果这两个请求地址没有其他参数的话声明两个接口方法不是感觉很累赘,所以Retrofit为我们提供了动态构造URL的方式来声明类似请求地址的接口方法。<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@GET</span>(<span class="string">"user/{path}"</span>)</div><div class="line"><span class="function">Call<User> <span class="title">getModelService</span><span class="params">(@Path(path)</span> String path, @<span class="title">Query</span><span class="params">(<span class="string">"param1"</span>)</span> <span class="keyword">boolean</span> param1, @<span class="title">Query</span><span class="params">(<span class="string">"param2"</span>)</span> <span class="keyword">boolean</span> param2)</span>;</div></pre></td></tr></table></figure></p>
<p>上面的方法中,<code>@GET</code>注解中<code>{path}</code>就代表URL可以动态变化的那一部分,<code>@Path</code>注解则表示该方法参数的值就是<code>{path}</code>中的动态值</p>
<h4 id="Post请求"><a href="#Post请求" class="headerlink" title="Post请求"></a>Post请求</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@FormUrlEncoded</span></div><div class="line"><span class="meta">@POST</span>(<span class="string">"postService"</span>)</div><div class="line"><span class="function">Call<String> <span class="title">postModelService</span><span class="params">(@Field(<span class="string">"msg"</span>)</span> String msg, @<span class="title">Field</span><span class="params">(<span class="string">"string"</span>)</span> <span class="keyword">boolean</span> isString)</span>;</div></pre></td></tr></table></figure>
<p>Retrofit中的Post请求则需要将前面的<code>@GET</code>注解换成<code>@POST</code>注解,而Post请求的文本参数则用注解<code>@Field</code>来声明,同时还必须给方法添加注解<code>@FormUrlEncoded</code>来告知Retrofit参数为表单参数,如果只为参数增加<code>@Field</code>注解,而不给方法添加<code>@FormUrlEncoded</code>注解运行时会抛异常。</p>
<p>如果Post请求有很多参数同样也可以使用集合的方式进行声明<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@FormUrlEncoded</span></div><div class="line"><span class="meta">@POST</span>(<span class="string">"{path}"</span>)</div><div class="line"><span class="function">Call<User> <span class="title">postModelService</span><span class="params">(@Path(<span class="string">"path"</span>)</span> String path, @FieldMap Map<String, String> map)</span>;</div></pre></td></tr></table></figure></p>
<p>Retrofit中提供了注解<code>@FieldMap</code>用来声明一个Map类型的集合作为Post请求的表单参数</p>
<p>Post请求的服务接口声明完成之后,讲得到的<code>Call</code>对象调用<code>execute</code>或者<code>enqueue</code>即可发起同步或异步的Post请求</p>
<p>以上就是Retrofit2的基本使用,下一篇文章我讲接着介绍Retrofit2中的文件上传和文件下载,以及如何实现文件上传和下载过程中的进度条</p>
<hr>
<p>原创文章,本文采用<a href="https://creativecommons.org/licenses/by/2.5/cn/" target="_blank" rel="external">知识共享署名 2.5(中国大陆许可协议)</a>进行许可,欢迎转载,但转载请注明来自<a href="ittiger.cn">ittiger.cn</a>,并保证转载后文章内容的完整性。本人(laohu)保留所有版权相关权利。</p>
</div>
<!-- 打赏 -->
<!-- css -->
<style type="text/css">
.center {
text-align: center;
}
.hidden {
display: none;
}
.donate_bar a.btn_donate{
display: inline-block;
width: 82px;
height: 82px;
background: url("http://7xsl28.com1.z0.glb.clouddn.com/btn_reward.gif") no-repeat;
_background: url("http://7xsl28.com1.z0.glb.clouddn.com/btn_reward.gif") no-repeat;
<!-- http://img.t.sinajs.cn/t5/style/images/apps_PRF/e_media/btn_reward.gif
因为本 hexo 生成的博客所用的 theme 的 a:hover 带动画效果,
为了在让打赏按钮显示效果正常 而 添加了以下几行 css,
嵌入其它博客时不一定要它们。 -->
-webkit-transition: background 0s;
-moz-transition: background 0s;
-o-transition: background 0s;
-ms-transition: background 0s;
transition: background 0s;
<!-- /让打赏按钮的效果显示正常 而 添加的几行 css 到此结束 -->
}
.donate_bar a.btn_donate:hover{ background-position: 0px -82px;}
.donate_bar .donate_txt {
display: block;
color: #9d9d9d;
font: 14px/2 "Microsoft Yahei";
}
.bold{ font-weight: bold; }
</style>
<!-- /css -->
<!-- Donate Module -->
<div id="donate_module">
<!-- btn_donate & tips -->
<div id="donate_board" class="donate_bar center">
<br>
<br>
<a id="btn_donate" class="btn_donate" target="_self" href="javascript:;" title="Donate 打赏"></a>
<span class="donate_txt">
对你有帮助?求鼓励,求支持!
</span>
</div>
<!-- /btn_donate & tips -->
<!-- donate guide -->
<div id="donate_guide" class="donate_bar center hidden">
<br>
<br>
<a href="http://ittiger.cn/img/weixinpay.png" title="用微信扫一扫哦~" class="fancybox" rel="article0">
<img src="http://ittiger.cn/img/weixinpay.png" title="微信打赏 Colin" height="200px" width="auto"/>
</a>
<a href="http://ittiger.cn/img/alipay.png" title="用支付宝扫一扫即可~" class="fancybox" rel="article0">
<img src="http://ittiger.cn/img/alipay.png" title="支付宝打赏 Colin" height="200px" width="auto"/>
</a>
<span class="donate_txt">
对你有帮助?求鼓励,求支持!
</span>
</div>
<!-- /donate guide -->
<!-- donate script -->
<script type="text/javascript">
document.getElementById('btn_donate').onclick = function() {
$('#donate_board').addClass('hidden');
$('#donate_guide').removeClass('hidden');
}
function donate_on_web(){
$('#donate').submit();
}
var original_window_onload = window.onload;
window.onload = function () {
if (original_window_onload) {
original_window_onload();
}
document.getElementById('donate_board_wdg').className = 'hidden';
}
</script>
<!-- /donate script -->
</div>
<br>
<br>
<!-- /Donate Module -->
<!-- 打赏 -->
<footer class="article-footer">
<div class="share-container">
<div class="bdsharebuttonbox">
<a href="#" class="bds_more" data-cmd="more">分享到:</a>
<a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间">QQ空间</a>
<a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博">新浪微博</a>
<a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博">腾讯微博</a>
<a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网">人人网</a>
<a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信">微信</a>
</div>
<script>
window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{"bdSize":16}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
</script>
<style>
.bdshare_popup_box {
border-radius: 4px;
border: #e1e1e1 solid 1px;
}
.bdshare-button-style0-16 a,
.bdshare-button-style0-16 .bds_more {
padding-left: 20px;
margin: 6px 10px 6px 0;
}
.bdshare_dialog_list a,
.bdshare_popup_list a,
.bdshare_popup_bottom a {
font-family: 'Microsoft Yahei';
}
.bdshare_popup_top {
display: none;
}
.bdshare_popup_bottom {
height: auto;
padding: 5px;
}
</style>
</div>
<a href="http://ittiger.cn/Retrofit2使用介绍.html#comments" class="article-comment-link ds-thread-count" data-thread-key="http://ittiger.cn/Retrofit2使用介绍.html">评论</a>
</footer>
</div>
<nav id="article-nav">
<a href="/Retrofit2文件上传下载及其进度显示.html" id="article-nav-newer" class="article-nav-link-wrap">
<strong class="article-nav-caption">上一篇</strong>
<div class="article-nav-title">
Retrofit2文件上传下载及其进度显示
</div>
</a>
<a href="/让RecyclerView更通用.html" id="article-nav-older" class="article-nav-link-wrap">
<strong class="article-nav-caption">下一篇</strong>
<div class="article-nav-title">让RecyclerView更通用</div>
</a>
</nav>
</article>
<section id="comments">
<div class="ds-thread" data-thread-key="Retrofit2使用介绍.html" data-title="Retrofit2使用介绍" data-url="http://ittiger.cn/Retrofit2使用介绍.html"></div>
<style>
#ds-thread #ds-reset .ds-textarea-wrapper {
background: none;
}
#ds-reset .ds-avatar img {
box-shadow: none;
}
#ds-reset .ds-gradient-bg {
background: #f7f7f7;
}
#ds-thread #ds-reset li.ds-tab a {
border-radius: 3px;
}
#ds-thread #ds-reset .ds-post-button {
color: white;
border: none;
box-shadow: none;
background: #d32;
text-shadow: none;
font-weight: normal;
font-family: 'Microsoft Yahei';
}
#ds-thread #ds-reset .ds-post-button:hover {
color: white;
background: #DE594C;
}
#ds-thread #ds-reset .ds-post-button:active {
background: #d32;
}
#ds-smilies-tooltip ul.ds-smilies-tabs li a.ds-current {
color: white;
background: #d32;
box-shadow: none;
text-shadow: none;
font-weight: normal;
}
</style>
</section>
</section>
<aside id="sidebar">
<div class="widget-wrap">
<h3 class="widget-title">最新文章</h3>
<div class="widget">
<ul id="recent-post" class="no-thumbnail">
<li>
<div class="item-inner">
<p class="item-category"><a class="article-category-link" href="/categories/小程序/">小程序</a></p>
<p class="item-title"><a href="/weixin-xcx-data-binding-and-params-transfer.html" class="title">微信小程序之页面数据绑定及页面跳转传参</a></p>
<p class="item-date"><time datetime="2017-07-17T09:50:02.000Z" itemprop="datePublished">2017-07-17</time></p>
</div>
</li>
<li>
<div class="item-inner">
<p class="item-category"><a class="article-category-link" href="/categories/小程序/">小程序</a></p>
<p class="item-title"><a href="/weixin-xcx-tabbar-switch.html" class="title">微信小程序之Tab切换</a></p>
<p class="item-date"><time datetime="2017-07-17T09:44:58.000Z" itemprop="datePublished">2017-07-17</time></p>
</div>
</li>
<li>
<div class="item-inner">
<p class="item-category"><a class="article-category-link" href="/categories/小程序/">小程序</a></p>
<p class="item-title"><a href="/weixin-xcx-first-project.html" class="title">微信小程序之入门项目</a></p>
<p class="item-date"><time datetime="2017-07-17T09:40:39.000Z" itemprop="datePublished">2017-07-17</time></p>
</div>
</li>
<li>
<div class="item-inner">
<p class="item-category"><a class="article-category-link" href="/categories/Android/">Android</a></p>
<p class="item-title"><a href="/TextSwitcher-ViewSwitcher.html" class="title">TextSwitcher与ViewSwitcher学习笔记</a></p>
<p class="item-date"><time datetime="2017-07-12T09:36:51.000Z" itemprop="datePublished">2017-07-12</time></p>
</div>
</li>
<li>
<div class="item-inner">
<p class="item-category"><a class="article-category-link" href="/categories/Media-Apps/">Media Apps</a></p>
<p class="item-title"><a href="/MediaBrowserService.html" class="title">关于媒体浏览器服务(MediaBrowserService)</a></p>
<p class="item-date"><time datetime="2017-04-30T13:45:04.000Z" itemprop="datePublished">2017-04-30</time></p>
</div>
</li>
</ul>
</div>
</div>
<div class="widget-wrap">
<h3 class="widget-title">分类</h3>
<div class="widget">
<ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Android/">Android</a><span class="category-list-count">34</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Blog/">Blog</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/">JavaScript</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Linux/">Linux</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Material-Design/">Material Design</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Media-Apps/">Media Apps</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/小程序/">小程序</a><span class="category-list-count">3</span></li></ul>
</div>
</div>
<div class="widget-wrap">
<h3 class="widget-title">归档</h3>
<div class="widget">
<ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">七月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">四月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/">三月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/02/">二月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/12/">十二月 2016</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/11/">十一月 2016</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/10/">十月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/09/">九月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/">八月 2016</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/07/">七月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/06/">六月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/05/">五月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/01/">一月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">十一月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/10/">十月 2015</a><span class="archive-list-count">10</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/09/">九月 2015</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/03/">三月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/12/">十二月 2014</a><span class="archive-list-count">1</span></li></ul>
</div>
</div>
<div class="widget-wrap">
<h3 class="widget-title">标签云</h3>
<div class="widget tagcloud">
<a href="/tags/9-png/" style="font-size: 12px;">9.png</a> <a href="/tags/Activity/" style="font-size: 10px;">Activity</a> <a href="/tags/Android/" style="font-size: 20px;">Android</a> <a href="/tags/AndroidStudio/" style="font-size: 10px;">AndroidStudio</a> <a href="/tags/Apache/" style="font-size: 10px;">Apache</a> <a href="/tags/Behavior/" style="font-size: 14px;">Behavior</a> <a href="/tags/Hexo/" style="font-size: 10px;">Hexo</a> <a href="/tags/IM/" style="font-size: 18px;">IM</a> <a href="/tags/IndexStickyView/" style="font-size: 10px;">IndexStickyView</a> <a href="/tags/JSONP/" style="font-size: 10px;">JSONP</a> <a href="/tags/Java/" style="font-size: 10px;">Java</a> <a href="/tags/JavaScript/" style="font-size: 10px;">JavaScript</a> <a href="/tags/Linux/" style="font-size: 18px;">Linux</a> <a href="/tags/Lucene/" style="font-size: 10px;">Lucene</a> <a href="/tags/Material-Design/" style="font-size: 14px;">Material Design</a> <a href="/tags/MediaBrowserService/" style="font-size: 10px;">MediaBrowserService</a> <a href="/tags/MediaControllerCompat/" style="font-size: 10px;">MediaControllerCompat</a> <a href="/tags/MySQL/" style="font-size: 10px;">MySQL</a> <a href="/tags/ORM/" style="font-size: 10px;">ORM</a> <a href="/tags/OkHttp/" style="font-size: 12px;">OkHttp</a> <a href="/tags/Openfire/" style="font-size: 18px;">Openfire</a> <a href="/tags/RecyclerView/" style="font-size: 16px;">RecyclerView</a> <a href="/tags/Retrofit/" style="font-size: 14px;">Retrofit</a> <a href="/tags/RxJava/" style="font-size: 10px;">RxJava</a> <a href="/tags/SQLite/" style="font-size: 10px;">SQLite</a> <a href="/tags/Shape/" style="font-size: 10px;">Shape</a> <a href="/tags/SpannableStringBuilder/" style="font-size: 10px;">SpannableStringBuilder</a> <a href="/tags/TableLayout/" style="font-size: 10px;">TableLayout</a> <a href="/tags/TextSwitcher/" style="font-size: 10px;">TextSwitcher</a> <a href="/tags/TextView/" style="font-size: 10px;">TextView</a> <a href="/tags/TigerDB/" style="font-size: 10px;">TigerDB</a> <a href="/tags/TigerOkHttp/" style="font-size: 10px;">TigerOkHttp</a> <a href="/tags/Tips/" style="font-size: 10px;">Tips</a> <a href="/tags/ViewSwitcher/" style="font-size: 10px;">ViewSwitcher</a> <a href="/tags/WordPress/" style="font-size: 18px;">WordPress</a> <a href="/tags/Zip解压/" style="font-size: 10px;">Zip解压</a> <a href="/tags/smack/" style="font-size: 18px;">smack</a> <a href="/tags/vsftpd/" style="font-size: 10px;">vsftpd</a> <a href="/tags/导航/" style="font-size: 10px;">导航</a> <a href="/tags/小程序/" style="font-size: 14px;">小程序</a> <a href="/tags/崩溃/" style="font-size: 10px;">崩溃</a> <a href="/tags/生命周期/" style="font-size: 10px;">生命周期</a> <a href="/tags/百度地图/" style="font-size: 10px;">百度地图</a> <a href="/tags/相机/" style="font-size: 12px;">相机</a> <a href="/tags/资源适配/" style="font-size: 10px;">资源适配</a> <a href="/tags/退出App/" style="font-size: 10px;">退出App</a> <a href="/tags/阿里云/" style="font-size: 18px;">阿里云</a>
</div>
</div>
<div class="widget-wrap widget-list">
<h3 class="widget-title">链接</h3>
<div class="widget">
<ul>
<li>
<a href="https://ashui.site/" rel="external nofollow">番羽土啬</a>
</li>
</ul>
</div>
</div>
<div id="toTop" class="fa fa-angle-up"></div>
</aside>
</div>
<footer id="footer">
<div class="outer">
<div id="footer-info" class="inner">
© 2017 老胡<br>
Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>. Theme by <a href="http://github.com/ppoffice">PPOffice</a>
</div>
</div>
</footer>
<script type="text/javascript">
var duoshuoQuery = {short_name:'ittiger'};
(function() {
var ds = document.createElement('script');
ds.type = 'text/javascript';ds.async = true;
ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
ds.charset = 'UTF-8';
(document.getElementsByTagName('head')[0]
|| document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
<script src="/libs/lightgallery/js/lightgallery.min.js"></script>
<script src="/libs/lightgallery/js/lg-thumbnail.min.js"></script>
<script src="/libs/lightgallery/js/lg-pager.min.js"></script>
<script src="/libs/lightgallery/js/lg-autoplay.min.js"></script>
<script src="/libs/lightgallery/js/lg-fullscreen.min.js"></script>
<script src="/libs/lightgallery/js/lg-zoom.min.js"></script>
<script src="/libs/lightgallery/js/lg-hash.min.js"></script>
<script src="/libs/lightgallery/js/lg-share.min.js"></script>
<script src="/libs/lightgallery/js/lg-video.min.js"></script>
<script src="/libs/justified-gallery/jquery.justifiedGallery.min.js"></script>
<!-- Custom Scripts -->
<script src="/js/main.js"></script>
</div>
</body>
</html>