Android開發(fā)的快捷功能

1.一個APP只需要一個Activity

? ? //片段fragment

? ? implementation 'me.yokeyword:fragmentation:1.3.6'

? ? implementation 'me.yokeyword:fragmentation-swipeback:1.3.6'

2.懶人必備查找控件

//ButterKnife(10.0必須適配AndroidX,9.0需要java8,快速生成插件android-butterknife-zelezny)

? ? implementation 'com.jakewharton:butterknife:9.0.0'

? ? annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0'

3.方法數(shù)超過65k,合并

a.引入jar包

? ? implementation "com.android.support:multidex:1.0.3"

b.配置合并dex為開啟

? ? defaultConfig {

? ? ? ? multiDexEnabled true

? ? }

c.在自己的MyApplication下的方法中初始化

? @Override

? ? protected void attachBaseContext(Context base) {

? ? ? ? super.attachBaseContext(base);

? ? ? ? MultiDex.install(this);

? ? }

4.新版本的Gradle,需要至少在一個Activity中的 <intent-filter>里面添加:

<action android:name="android.intent.action.VIEW" />

5.拉的自己封裝的工具類需要去掉,.git的關(guān)聯(lián)

https://blog.csdn.net/lyj1005353553/article/details/55519487

6.設(shè)置去掉所有的頁面標題欄

在AppTheme中配置

<item name="windowNoTitle">true</item>

7.快速構(gòu)建Builder插件

innerbuilder插件

8.使用Dagger2無法找到對于的Component類查牌,

a.必須在基類的onCreate方法中注入

? ? @Override

? ? public void onCreate(@Nullable Bundle savedInstanceState) {

? ? ? ? super.onCreate(savedInstanceState);

? ? ? ? DaggerCommonComponent.create().inject(this);

? ? }

而不要注入到另一個onCreate中

? ? @Override

? ? public void onCreate( @Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {

? ? ? ? super.onCreate(savedInstanceState, persistentState);


? ? }

9.RecyclerView嵌套ScrollView不流暢

recyclerView.setHasFixedSize(true);

recyclerView.setNestedScrollingEnabled(false);

垂直滑動問題:

https://segmentfault.com/a/1190000011553735

recyclerview嵌套在NestedScrollView里,一次性加載出全部數(shù)據(jù)問題

https://github.com/CymChad/BaseRecyclerViewAdapterHelper/issues/1954

Android SwipeRefreshLayout和RecyclerView嵌套時 下拉刷新沖突的解決辦法

https://blog.csdn.net/peirato_/article/details/54913195

針對RecyclerView不顯示

只需要設(shè)置ScrollView的屬性android:layout_height="match_parent" android:fillViewport="true" 就OK了训桶。

監(jiān)聽RecyclerView滾動距離

//RecyclerView滾動監(jiān)聽

? ? ? ? recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

? ? ? ? ? ? @Override

? ? ? ? ? ? public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {

? ? ? ? ? ? ? ? super.onScrollStateChanged(recyclerView, newState);

? ? ? ? ? ? ? ? switch (newState){

? ? ? ? ? ? ? ? ? ? case RecyclerView.SCROLL_STATE_IDLE://現(xiàn)在不是滾動狀態(tài)

? ? ? ? ? ? ? ? ? ? ? ? L.e("滾動的距離=="+direction);

? ? ? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? ? ? case RecyclerView.SCROLL_STATE_DRAGGING://手指 拖動

? ? ? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? ? ? case RecyclerView.SCROLL_STATE_SETTLING://慣性滾動

? ? ? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? @Override

? ? ? ? ? ? public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {

? ? ? ? ? ? ? ? super.onScrolled(recyclerView, dx, dy);

? ? ? ? ? ? ? ? //計算RecyclerView滾動的距離

? ? ? ? ? ? ? ? direction += dy;

? ? ? ? ? ? }

? ? ? ? });

10.Retrofit網(wǎng)絡(luò)請求枫浙,生成

private static void setRetrofit(String defaultHost) {

? ? ? ? retrofit = new Retrofit.Builder()

? ? ? ? ? ? ? ? ? ? ? ? .baseUrl(defaultHost)

? ? ? ? ? ? ? ? ? ? ? ? .client(okHttpClient)

? ? ? ? ? ? ? ? ? ? ? ? .addCallAdapterFactory(RxJava2CallAdapterFactory.create())

? ? ? ? ? ? ? ? ? ? ? ? .addConverterFactory(JSONObjectConverterFactory.create())

? ? ? ? ? ? ? ? ? ? ? ? .addConverterFactory(GsonConverterFactory.create()).build();

? ? }

其中JSONObjectConverterFactory和GsonConverterFactory不能共存匾委,如果想返回JSONObject對象让虐,去掉 .addConverterFactory(GsonConverterFactory.create())如果想直接生成Object對象谍夭,去掉.addConverterFactory(JSONObjectConverterFactory.create())

11.TextView加入刪除線

tv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);

代碼中繪制左側(cè)圖片

Drawable img = layout.getResources().getDrawable(R.drawable.icon);?

// 調(diào)用setCompoundDrawables時黑滴,必須調(diào)用Drawable.setBounds()方法,否則圖片不顯示?

img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight());?

textView.setCompoundDrawables(img, null, null, null); //設(shè)置左圖標?

文字滾動消息:

< TextView

? ? ? ? android:layout_width ="wrap_content"

? ? ? ? android:layout_height ="wrap_content"

? ? ? ? android:focusable ="true"

? ? ? ? android:focusableInTouchMode ="true"

? ? ? ? android:marqueeRepeatLimit ="marquee_forever"

? ? ? ? android:ellipsize ="marquee"

? ? ? ? android:singleLine ="true"

? ? ? ? android:text ="那么什么是成功的人生,什么樣的人又是成功人士呢紧索?像科技界的比爾袁辈?蓋茨 ,喬布斯 珠漂,商界的巴菲特以及娛樂晚缩、體育界的大腕,無疑會被人們視為是成功者媳危。但對于普通民眾荞彼,如果用比爾?蓋茨那樣的標準來衡量是否成功似乎有些太苛刻待笑,也不現(xiàn)實鸣皂。在某種觀念中,一個人的成功似乎與財富分不開的暮蹂。很多國人到美國看到華人最常說的一句話是寞缝,你是個成功人士。為什么這么說仰泻?因為你能住300平方米荆陆、價值百萬美元的房子,因為你開的車是奔馳 集侯、寶馬等豪華車被啼,因為你有好的工作帜消,年薪至少在10萬美元以上。這也許是很多國人看待一個人成功與否的主要標志趟据。但在美國人眼里券犁,成功并不是與擁有眾多財富密不可分。在1980年代汹碱,多數(shù)美國人把擁有更多財富看成人生成功的一個主要標志粘衬。而在一項最新的調(diào)查中,對于美國人來說咳促,財富不再是成功的最重要組成部分稚新。調(diào)查中22個成功人生的潛在組成因素中,“有很多錢”僅排名在第20位跪腹。" />

12.對Retrofit回調(diào)進行封裝褂删,只輸出正確和錯誤信息

自定義Retrofit網(wǎng)絡(luò)回調(diào)結(jié)果

13.EditText變搜索按鈕,并監(jiān)聽搜索事件

https://www.cnblogs.com/epmouse/p/6237274.html

14.CoordinatorLayout布局要設(shè)置滾動控件的

app:layout_behavior="@string/appbar_scrolling_view_behavior"

里面的字符串爆紅冲茸,但還是可以運行屯阀,但紅色總是不好看的,可能是新版本的sdk引起的轴术,所以需要改為

app:layout_behavior ="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"

15.WebView不跳轉(zhuǎn)到外部瀏覽器

class MyWebViewClient extends WebViewClient{

? ? ? ? //不跳轉(zhuǎn)到外部瀏覽器

? ? ? ? public boolean shouldOverrideUrlLoading(WebView view, String url) {

? ? ? ? ? ? view.loadUrl(url);

? ? ? ? ? ? return true;

? ? ? ? }

? ? }

Android webview loadData 中文亂碼

http://www.reibang.com/p/85957f003dd4

16.WebView出現(xiàn)net::ERR_UNKNOWN_URL_SCHEME錯誤

http://www.reibang.com/p/119823e5cfb5

17.Glide顯示圖片為上面圓角难衰,下面直角

讓Glide輸出指定位置的圓角圖片 2018年,部分方法為Glide4.0以前的逗栽,所以無法使用盖袭,但方法值得借鑒

Glide 加載部分圓角圖片2019年,新的方法彼宠,且行為更合理

圓角不圓:有可能是因為圖片高度或?qū)挾冗^大鳄虱,導(dǎo)致部分圓角不圓

Glide ViewTarget及SimpleTarget加載問題:

18.View轉(zhuǎn)換為Bitmap

關(guān)于View轉(zhuǎn)化成bitmap保存成圖片

兩個Bitmap合并為一個

Android:將一個Activity、某塊布局轉(zhuǎn)換成圖片

19.使用xml繪制虛線好后凭峡,4.0以上需要使用 android:layerType="software"屬性拙已,不然虛線會變?yōu)閷嵕€

https://blog.csdn.net/Small_Lee/article/details/52153557

20.微信分享到朋友圈,調(diào)用系統(tǒng)分享摧冀,需要對Uri單獨處理一下

https://blog.csdn.net/qq_34900897/article/details/85320646

21.support版本沖突的解決辦法

https://blog.csdn.net/yuzhiqiang_1993/article/details/78214812

22.TabLayout+ViewPager垂直方向聯(lián)動悠栓,用于分類頁面

http://www.reibang.com/p/9266e58cc4f5

23.精確計算RecyclerView滑動高度

SlideRecyclerView

24.adb無線調(diào)試

https://jingyan.baidu.com/article/066074d610f4f3c3c21cb0ab.html

25.打包名稱自定義

https://www.cnblogs.com/bluestorm/p/6228085.html

https://blog.csdn.net/weixin_33709364/article/details/87160660

打包方法過時警告:https://www.cnblogs.com/blogs-of-lxl/p/10306145.html

我的通用命名方式:包名最后一部分+版本名稱+時間+打包方式 taobao_v1.0_2019-05-20_release

在android{}里面寫入

android.applicationVariants.all { variant ->

? ? ? ? variant.outputs.all{

? ? ? ? ? ? outputFileName? = "${applicationId.subSequence(applicationId.lastIndexOf(".")+1,applicationId.length())}_v${versionName}_${releaseTime()}_${baseName}.apk"

? ? ? ? }

? ? }

其中releaseTime()為寫在android{}外部的一個方法

def releaseTime() {

? ? return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))

}

26.apk簽名打包

如何配置簽名:

https://www.cnblogs.com/details-666/p/keystore.html

如何判斷你的apk是否已經(jīng)簽名:

https://blog.csdn.net/qq_21376985/article/details/53337977

27.混淆

https://blog.csdn.net/qq634416025/article/details/79686051

28.TextView設(shè)置可滾動的方式

xml中設(shè)置TextView屬性

android:scrollbars="vertical"

同時代碼中設(shè)置

textView.setMovementMethod(ScrollingMovementMethod.getInstance());

29.Android:通過Glide保存圖片到本地,并同步到相冊

30.Android 調(diào)用系統(tǒng)分享(不使用第三方)按价,指定QQ、微信等

https://blog.csdn.net/u010356768/article/details/78246691

qq空間限制:

https://blog.csdn.net/weixin_41239127/article/details/78743421

31.安卓從imageview中獲得bitmap的方法

https://blog.csdn.net/yj1499945/article/details/47079621

32.怎樣獲取到Android控件的高度笙瑟,通過監(jiān)聽的方式

http://www.reibang.com/p/2c8e5324ec68

你可能也不知道為什么楼镐,第一次進入頁面,獲取控件的高度有值往枷,再次進入獲取的高度居然為0框产,再再再次進入也為0凄杯,殺掉應(yīng)用,進入頁面又有高度了秉宿,再次進入又為0戒突。因為我需要通過view來獲取Bitmap,那么View的寬高值必不可少,所以我通過上面博客的方法去監(jiān)聽控件的高度才拿到值描睦。但為什么只有第一次進入才能拿到寬高值卻拜師不得琪姐膊存,請各位大老解答。

33.AccessibilityService獲取控件信息getRootInActiveWindow() 經(jīng)常為null

https://blog.csdn.net/qq_28210079/article/details/80486592

33.解決android.permission.WRITE_APN_SETTINGS

https://blog.csdn.net/qq_36437339/article/details/81015715

34.新手引導(dǎo)庫

GuideView

在Fragment中由于控件位置繪制流程和生命周期的關(guān)系忱叭,需要監(jiān)聽控件View寬高隔崎,有值后才進行引導(dǎo)層的繪制,同時用Handler進行一定的延遲繪制韵丑,保證高亮區(qū)域的定位精確度

35.Java中對對象進行排序

https://blog.csdn.net/qq_37937537/article/details/80445731

通過Comparable

36.監(jiān)控當前APP是否回到前臺

http://www.reibang.com/p/101eb42d0fde

37.使用java8新特性快速的打印輸出序列對象

allList.stream().map(User::toString).forEach(L::e);

38.Fragment的優(yōu)化

不要再Activity中使用List來保存Fragment

https://blog.csdn.net/qq_30993595/article/details/80736814

39.ViewPager2,支持橫豎布局爵卒,支持0預(yù)加載布局

https://juejin.im/post/5cda3964f265da035d0c9d8f

40.RadioGroup.onCheckedChanged() 會調(diào)用多次

https://blog.csdn.net/qq_32452623/article/details/80474487

41.Retrifit2上傳圖片

https://www.cnblogs.com/zhujiabin/p/7601658.html

42.Java多線程

Java多線程系列目錄(共43篇)

43.ArrayList進行排序

24版本以前的老方法:

Collections.sort(arrays);

新方法

arrays.sort();

44.對時間的轉(zhuǎn)換,對比撵彻,添加钓株,格式輸出

joda-time

45. tools:replace的使用

tools:replace=""有時候需要替換多個項,使用逗號分割

tools:replace="android:allowBackup,android:appComponentFactory"

46. 解決 導(dǎo)入三方時出現(xiàn): appComponentFactory 錯誤

https://blog.csdn.net/qq_34224268/article/details/83861897

47. 滾輪時間選擇器

可以采用 XPopup和WheelPicker

組合的方式來生成一個時間選擇器如:http://www.reibang.com/p/4a2c853d9276

48. fragment里coordinatorlayout+viewpager無法正衬敖滑動問題

fragment里coordinatorlayout+viewpager無法正持岷希滑動問題

有人說fragment是無法運行協(xié)調(diào)者布局的,這是錯誤的

解決方法:在你的viewpager子fragment里面布局最外面套上一層NestedScrollView就可以了

49.查看SHA1命令

keytool -list -v -keystore C:\Users\Desktop\browser\debug.keystore -storepass android

50.RecyclerView橫向分頁菜單

https://blog.csdn.net/u014165119/article/details/46834265

51.ArgbEvaluator一個計算顏色漸變值的類

https://blog.csdn.net/u013581141/article/details/68063469

使用事例:自定義CoordinatorLayout.Behavior顏色漸變的TitleBar

52.交互效果咋了系列:

自定義ViewGroup第十三式之移花接木

53.數(shù)據(jù)綁定DataBind

android {

? ? …

? ? dataBinding {

? ? ? ? enabled = true

? ? }

}

告別findView和ButterKnife

Android開發(fā)教程 - 使用Data Binding(七)使用BindingAdapter簡化圖片加載

54.錯誤檢查命令

gradlew processDebugManifest --stacktrace

55.new Handler的警告說明和解決辦法@SuppressLint(“HandlerLeak”)

https://blog.csdn.net/androidsj/article/details/79865091

? ? private MyHandler myHandler = new MyHandler(_mActivity);

? ? private static class MyHandler extends Handler {

? ? ? ? WeakReference weakReference;

? ? ? ? public MyHandler(Activity activity) {

? ? ? ? ? ? weakReference = new WeakReference(activity);

? ? ? ? }

? ? ? ? @Override

? ? ? ? public void handleMessage(Message msg) {

? ? ? ? }

? ? }

另一種寫法:

private Handler mHandler = new Handler(new Handler.Callback() {

? ? ? ? @Override

? ? ? ? public boolean handleMessage(Message msg) {

? ? ? ? ? ? return false;

? ? ? ? }

? ? });

56.多行且需要最后顯示省略號的警告處理

logcat 總是報: W/StaticLayout: maxLineHeight should not be -1. maxLines:1 lineCount:1

57.通知無法顯示:8.0需要設(shè)置渠道和權(quán)重

http://www.reibang.com/p/f85ef58edf63

58.uri指向了外部應(yīng)用exposed beyond app through RemoteViews.setUri()

在Application中的onCreate方法中添加如下

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();

? ? ? ? StrictMode.setVmPolicy(builder.build());

? ? ? ? builder.detectFileUriExposure();

59.解決因為彈窗導(dǎo)致TextView停止?jié)L動的問題:

http://www.reibang.com/p/22b4aff0dc8e

60.彈窗需要一個自定義的三角形SanJiaoView :

https://blog.csdn.net/ZhangLei280/article/details/73207669

61.升級AndroidX后出現(xiàn)缺失AppBarLayout$ScrollingViewBehavior

http://www.reibang.com/p/6b8104787617

62.APP啟動時間拾弃,性能優(yōu)化值桩,啟動頁白屏

http://www.reibang.com/p/75b0b128c470

63.AndroidStudio安裝失敗

image.png

方法一:clean項目

方法二:重啟大法:重啟AndroidStudio,重啟手機,重啟電腦豪椿,重啟...

方法三:檢查是否只開啟了開發(fā)者模式和USB調(diào)試奔坟,卻沒有開啟了USB安裝

image.png

64.adb命令

http://www.reibang.com/p/56fd03f1aaae

65.ConstraintLayout基礎(chǔ) 及動態(tài)控件(動畫效果)

http://www.reibang.com/p/7888cde8292f

66.獲取videoView第一針視頻報錯:

https://blog.csdn.net/guohesheng/article/details/80236799

67.Math函數(shù)相關(guān)計算

//角度換算為對應(yīng)數(shù)值

double skewRot = Math.toRadians(30);

68. banner庫一張圖片無效和第一次進入沒有輪播的時候點擊第一張無效

一張圖片的時候需要設(shè)置banner的onClick事件,多張圖第一次還未開始輪播點擊無效搭盾,需要先設(shè)置點擊事件咳秉,再調(diào)用banner的start方法

69. <activity-alias> 標簽的使用

<activity-alias> 標簽的使用

70.Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK

https://blog.csdn.net/watermusicyes/article/details/44963773

71.程序崩潰日志收集

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

? ? ? ? ? ? @Override

? ? ? ? ? ? public void uncaughtException(Thread thread, final Throwable ex) {

? ? ? ? ? ? ? ? // Custom code here to handle the error.

? ? ? ? ? ? ? ? L.e("發(fā)生崩潰=="+thread.getName()+"? =="+ex.getMessage());

? ? ? ? ? ? }

? ? ? ? });

72.Android Q正式發(fā)布。新一代的安卓系統(tǒng)非常注重對用戶隱私的保護鸯隅,它限制APP獲取IMEI澜建、DEVICE ID等移動端設(shè)備標識碼,解決方案:

簡書:http://www.reibang.com/p/df3f549ddd35

官方:https://developer.android.google.cn/training/articles/user-data-ids

73.再按一次退出程序

? ? private long firstTime = 0;

? ? @Override

? ? public boolean onKeyUp(int keyCode, KeyEvent event) {

? ? ? ? switch (keyCode) {

? ? ? ? ? ? case KeyEvent.KEYCODE_BACK:

? ? ? ? ? ? ? ? long secondTime = System.currentTimeMillis();

? ? ? ? ? ? ? ? //如果兩次按鍵時間間隔大于2秒蝌以,則不退出

? ? ? ? ? ? ? ? if (secondTime - firstTime > 2000) {

? ? ? ? ? ? ? ? ? ? Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();

? ? ? ? ? ? ? ? ? ? firstTime = secondTime;//更新firstTime

? ? ? ? ? ? ? ? ? ? return true;

? ? ? ? ? ? ? ? ? ? //兩次按鍵小于2秒時炕舵,退出應(yīng)用

? ? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? ? System.exit(0);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? break;

? ? ? ? }

? ? ? ? return super.onKeyUp(keyCode, event);

? ? }

如果是Fragment請不要復(fù)寫onBackPressed()方法,改為復(fù)寫onBackPressedSupport():

? ? //再按一次退出程序

? ? private long firstTime = 0;

? ? @Override

? ? public void onBackPressedSupport() {

? ? ? ? long secondTime = System.currentTimeMillis();

? ? ? ? if (getSupportFragmentManager().getBackStackEntryCount() == 1 && secondTime - firstTime > 2000) {

? ? ? ? ? ? Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();

? ? ? ? ? ? firstTime = secondTime;

? ? ? ? } else {

? ? ? ? ? ? super.onBackPressedSupport();

? ? ? ? }

? ? }

74.AndroidX升級日記

http://www.reibang.com/p/55645eb89214

75.AndroidStudio啟動模擬器Android10.0報錯

Emulator: Process finished with exit code -1073741819 (0xC0000005)

https://stackoverflow.com/questions/47631771/emulator-process-finished-with-exit-code-1073741819-0xc0000005

76.簡單實現(xiàn)ImageView寬度填滿屏幕跟畅,高度自適應(yīng)的兩種方式

http://www.reibang.com/p/c9424615e99d

77.RecyclerView瀑布流問題

http://www.reibang.com/p/4e142909b824

https://blog.csdn.net/tobevan/article/details/78924338

78.android studio關(guān)閉字符串資源多語言提示

https://blog.csdn.net/sinat_26814541/article/details/97757535

79.ConstraintLayout 采用代碼方式布局用法簡介

http://xgfe.github.io/2017/09/17/ivanchou/layout-with-constraintlayout-by-programming/

80.Glide獲得圖片資源咽筋,并高斯模糊

? ? ? ? try {

? ? ? ? ? ? Drawable drawable = Glide.with(mContext)

? ? ? ? ? ? ? ? ? ? .load(item.getImage_url())

? ? ? ? ? ? ? ? ? ? .apply(RequestOptions.bitmapTransform(new BlurTransformation(15, 1)))

? ? ? ? ? ? ? ? ? ? .submit().get();

? ? ? ? ? ? layoutRoot.setBackground(drawable);

? ? ? ? } catch (ExecutionException e) {

? ? ? ? ? ? e.printStackTrace();

? ? ? ? } catch (InterruptedException e) {

? ? ? ? ? ? e.printStackTrace();

? ? ? ? }

高斯模糊

public class BlurTransformation extends BitmapTransformation {

? ? private static final int VERSION = 1;

? ? private static final String ID = "BlurTransformation." + VERSION;

? ? private static int MAX_RADIUS = 25;

? ? private static int DEFAULT_DOWN_SAMPLING = 1;

? ? private int radius;

? ? private int sampling;

? ? public BlurTransformation() {

? ? ? ? this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);

? ? }

? ? public BlurTransformation(int radius) {

? ? ? ? this(radius, DEFAULT_DOWN_SAMPLING);

? ? }

? ? public BlurTransformation(int radius, int sampling) {

? ? ? ? this.radius = radius;

? ? ? ? this.sampling = sampling;

? ? }

? ? @Override

? ? protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {

? ? ? ? int width = toTransform.getWidth();

? ? ? ? int height = toTransform.getHeight();

? ? ? ? int scaledWidth = width / sampling;

? ? ? ? int scaledHeight = height / sampling;

? ? ? ? Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);

? ? ? ? Canvas canvas = new Canvas(bitmap);

? ? ? ? canvas.scale(1 / (float) sampling, 1 / (float) sampling);

? ? ? ? Paint paint = new Paint();

? ? ? ? paint.setFlags(Paint.FILTER_BITMAP_FLAG);

? ? ? ? canvas.drawBitmap(toTransform, 0, 0, paint);

? ? ? ? bitmap = FastBlur.blur(bitmap, radius, true);

? ? ? ? return bitmap;

? ? }

? ? @Override public String toString() {

? ? ? ? return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";

? ? }

? ? @Override public boolean equals(Object o) {

? ? ? ? return o instanceof BlurTransformation &&

? ? ? ? ? ? ? ? ((BlurTransformation) o).radius == radius &&

? ? ? ? ? ? ? ? ((BlurTransformation) o).sampling == sampling;

? ? }

? ? @Override public int hashCode() {

? ? ? ? return ID.hashCode() + radius * 1000 + sampling * 10;

? ? }

? ? @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {

? ? ? ? messageDigest.update((ID + radius + sampling).getBytes(CHARSET));

? ? }

}

81.Glide獲得獲取圖片主體色系

? Glide.with(mContext).load(item.getImage_url())

? ? ? ? ? ? ? ? .listener(GlidePalette.with(item.getImage_url())

? ? ? ? ? ? ? ? ? ? ? ? .use(GlidePalette.Profile.VIBRANT)

? ? ? ? ? ? ? ? ? ? ? ? .intoBackground(layoutRoot, GlidePalette.Swatch.RGB)

? ? ? ? ? ? ? ? ? ? ? ? .crossfade(true)

? ? ? ? ? ? ? ? ).into(imageView);

82.Android獲取內(nèi)網(wǎng)IP

方法一:

? package com.rongyan.clienttest;

import java.net.InetAddress;

import java.net.NetworkInterface;

import java.net.SocketException;

import java.util.Enumeration;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class NetWorkUtil {

? ? //匹配C類地址的IP

? ? public static final String regexCIp = "^192\\.168\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)$";

? ? //匹配A類地址

? ? public static final String regexAIp = "^10\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)$";

? ? //匹配B類地址

? ? public static final String regexBIp = "^172\\.(1[6-9]|2\\d|3[0-1])\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)$";

? ? public static String getHostIp() {

? ? ? ? String hostIp;

? ? ? ? Pattern ip = Pattern.compile("(" + regexAIp + ")|" + "(" + regexBIp + ")|" + "(" + regexCIp + ")");

? ? ? ? Enumeration<NetworkInterface> networkInterfaces = null;

? ? ? ? try {

? ? ? ? ? ? networkInterfaces = NetworkInterface.getNetworkInterfaces();

? ? ? ? } catch (SocketException e) {

? ? ? ? ? ? e.printStackTrace();

? ? ? ? }

? ? ? ? InetAddress address;

? ? ? ? while (networkInterfaces.hasMoreElements()) {

? ? ? ? ? ? NetworkInterface networkInterface = networkInterfaces.nextElement();

? ? ? ? ? ? Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();

? ? ? ? ? ? while (inetAddresses.hasMoreElements()) {

? ? ? ? ? ? ? ? address = inetAddresses.nextElement();

? ? ? ? ? ? ? ? String hostAddress = address.getHostAddress();

? ? ? ? ? ? ? ? Matcher matcher = ip.matcher(hostAddress);

? ? ? ? ? ? ? ? if (matcher.matches()) {

? ? ? ? ? ? ? ? ? ? hostIp = hostAddress;

? ? ? ? ? ? ? ? ? ? return hostIp;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? return null;

? ? }

}

方法二:

? ? public String getWifiIp() {

? ? ? ? //獲取wifi服務(wù)

? ? ? ? WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);

? ? ? ? //判斷wifi是否開啟

? ? ? ? if (!wifiManager.isWifiEnabled()) {

? ? ? ? ? ? wifiManager.setWifiEnabled(true);

? ? ? ? }

? ? ? ? WifiInfo wifiInfo = wifiManager.getConnectionInfo();

? ? ? ? int ipAddress = wifiInfo.getIpAddress();

? ? ? ? return intToIp(ipAddress);

? ? }

? ? //獲取Wifi ip 地址

? ? private String intToIp(int i) {

? ? ? ? return (i & 0xFF) + "." +

? ? ? ? ? ? ? ? ((i >> 8) & 0xFF) + "." +

? ? ? ? ? ? ? ? ((i >> 16) & 0xFF) + "." +

? ? ? ? ? ? ? ? (i >> 24 & 0xFF);

? ? }

參考:https://www.cnblogs.com/jxust-jiege666/p/8168149.html

83.Android獲取外網(wǎng)IP

參考:http://www.reibang.com/p/1e3eaf887191

方法一,通過訪問第三方接口地址來獲取

import org.json.JSONException;

import org.json.JSONObject;

/**

? ? * 獲取外網(wǎng)IP地址

? ? * @return

? ? */

? ? public void GetNetIp() {

? ? ? ? new Thread(){

? ? ? ? ? ? @Override

? ? ? ? ? ? public void run() {

? ? ? ? ? ? ? ? String line = "";

? ? ? ? ? ? ? ? URL infoUrl = null;

? ? ? ? ? ? ? ? InputStream inStream = null;

? ? ? ? ? ? ? ? try {

? ? ? ? ? ? ? ? ? ? infoUrl = new URL("http://pv.sohu.com/cityjson?ie=utf-8");

? ? ? ? ? ? ? ? ? ? URLConnection connection = infoUrl.openConnection();

? ? ? ? ? ? ? ? ? ? HttpURLConnection httpConnection = (HttpURLConnection) connection;

? ? ? ? ? ? ? ? ? ? int responseCode = httpConnection.getResponseCode();

? ? ? ? ? ? ? ? ? ? if (responseCode == HttpURLConnection.HTTP_OK) {

? ? ? ? ? ? ? ? ? ? ? ? inStream = httpConnection.getInputStream();

? ? ? ? ? ? ? ? ? ? ? ? BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, "utf-8"));

? ? ? ? ? ? ? ? ? ? ? ? StringBuilder strber = new StringBuilder();

? ? ? ? ? ? ? ? ? ? ? ? while ((line = reader.readLine()) != null)

? ? ? ? ? ? ? ? ? ? ? ? ? ? strber.append(line + "\n");

? ? ? ? ? ? ? ? ? ? ? ? inStream.close();

? ? ? ? ? ? ? ? ? ? ? ? // 從反饋的結(jié)果中提取出IP地址

? ? ? ? ? ? ? ? ? ? ? ? int start = strber.indexOf("{");

? ? ? ? ? ? ? ? ? ? ? ? int end = strber.indexOf("}");

? ? ? ? ? ? ? ? ? ? ? ? String json = strber.substring(start, end + 1);

? ? ? ? ? ? ? ? ? ? ? ? if (json != null) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? JSONObject jsonObject = null;

? ? ? ? ? ? ? ? ? ? ? ? ? ? try {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? jsonObject = new JSONObject(json);

? ? ? ? ? ? ? ? ? ? ? ? ? ? } catch (JSONException e) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? e.printStackTrace();

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? line = jsonObject.optString("cip");

? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? L.e("line=="+line);

? ? ? ? ? ? ? ? ? ? ? ? Message msg = new Message();

? ? ? ? ? ? ? ? ? ? ? ? msg.what = 1;

? ? ? ? ? ? ? ? ? ? ? ? msg.obj = line;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? } catch (MalformedURLException e) {

? ? ? ? ? ? ? ? ? ? e.printStackTrace();

? ? ? ? ? ? ? ? } catch (IOException e) {

? ? ? ? ? ? ? ? ? ? e.printStackTrace();

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }.start();

? ? }

84.顏色均勻漸變的動畫

ValueAnimator animator = ValueAnimator.ofInt(0xffffff00,0xff0000ff);

animator.setEvaluator(new ArgbEvaluator());

animator.setDuration(3000);

animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

? ? @Override

? ? public void onAnimationUpdate(ValueAnimator animation) {

? ? ? ? int curValue = (int)animation.getAnimatedValue();

? ? ? ? tv.setBackgroundColor(curValue);

? ? }

});

animator.start();

85.Android的cpu架構(gòu)7種

參考:https://blog.csdn.net/u012400885/article/details/52923765

http://www.reibang.com/p/f29ad4beef59

86.'gradle' 不是內(nèi)部或外部命令徊件,也不是可運行的程序 或批處理文件

https://blog.csdn.net/u014743890/article/details/84316176

87.使用ImmersionBar時奸攻,加載出現(xiàn)Dialog的顯示會導(dǎo)致導(dǎo)航欄出現(xiàn)不消失:

88.Dagger2-Android不支持泛型Activity的注入

https://blog.csdn.net/ybf326/article/details/82931587

89.邀請碼識別來源

https://www.openinstall.io/

90.Android 自動抓取網(wǎng)站圖標實現(xiàn)分享樣式的定制

https://blog.csdn.net/dnsliu/article/details/57122535

91.Fragment實現(xiàn)懶加載

https://blog.csdn.net/vic6329063/article/details/82838430

92.版權(quán)登記

http://www.ccopyright.com/index.php?optionid=1216

93.獲取隨機顏色值

分別取rgb的隨機值(0~256)蒜危,然后加起來就是一個隨機顏色值,通過Color.parseColor()轉(zhuǎn)為color值即可使用:

public static String getRandColor() {

? ? ? ? String R, G, B;

? ? ? ? Random random = new Random();

? ? ? ? R = Integer.toHexString(random.nextInt(256)).toUpperCase();

? ? ? ? G = Integer.toHexString(random.nextInt(256)).toUpperCase();

? ? ? ? B = Integer.toHexString(random.nextInt(256)).toUpperCase();

? ? ? ? R = R.length() == 1 ? "0" + R : R;

? ? ? ? G = G.length() == 1 ? "0" + G : G;

? ? ? ? B = B.length() == 1 ? "0" + B : B;

? ? ? ? return "#" + R + G + B;

? ? }

94.Glide設(shè)置圓角圖片后設(shè)置ImageVIew的scanType="centerCrop"無效解決辦法

http://www.reibang.com/p/95d3f64a48dc

RequestOptions options = new RequestOptions()

? ? ? ? ? ? ? ? .transform(new CenterCrop(),new RoundedCorners(18))

? ? ? ? ? ? ? ? .placeholder(R.drawable.no_banner)

? ? ? ? ? ? ? ? .error(R.drawable.no_banner);

? ? ? ? Glide.with(context).load(path)

? ? ? ? ? ? ? ? .apply(options)

? ? ? ? ? ? ? ? .thumbnail(0.1f)

? ? ? ? ? ? ? ? .into(imageView);

95.線性漸變字體

https://blog.csdn.net/negineko/article/details/100033250

public class GradientColorTextView extends AppCompatTextView {

? ? private Rect mTextBound = new Rect();

? ? public GradientColorTextView (Context context, AttributeSet attrs) {

? ? ? ? super(context, attrs);

? ? }

? ? @Override

? ? protected void onDraw(Canvas canvas) {

? ? ? ? int mViewWidth = getMeasuredWidth();

? ? ? ? Paint mPaint = getPaint();

? ? ? ? String mTipText = getText().toString();

? ? ? ? mPaint.getTextBounds(mTipText, 0, mTipText.length(), mTextBound);

? ? ? ? @SuppressLint("DrawAllocation") LinearGradient mLinearGradient = new LinearGradient(0, 0, mViewWidth, 0, new int[]{0xFFFF0000, 0xFF5400FF}, null, Shader.TileMode.REPEAT);

? ? ? ? mPaint.setShader(mLinearGradient);

? ? ? ? canvas.drawText(mTipText, getMeasuredWidth() / 2 - mTextBound.width() / 2, getMeasuredHeight() / 2 + mTextBound.height() / 2, mPaint);

? ? }

}

96.TextView 設(shè)置其他字體后,顯示不全的問題

https://blog.csdn.net/u010979599/article/details/86650297

http://www.reibang.com/p/4314cc68c1f3

97.Android視頻播放睹耐,選擇辐赞,壓縮,上傳

http://www.reibang.com/p/78b7176c041e

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末硝训,一起剝皮案震驚了整個濱河市响委,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌捎迫,老刑警劉巖晃酒,帶你破解...
    沈念sama閱讀 212,454評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異窄绒,居然都是意外死亡贝次,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,553評論 3 385
  • 文/潘曉璐 我一進店門彰导,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蛔翅,“玉大人,你說我怎么就攤上這事位谋∩轿觯” “怎么了?”我有些...
    開封第一講書人閱讀 157,921評論 0 348
  • 文/不壞的土叔 我叫張陵掏父,是天一觀的道長笋轨。 經(jīng)常有香客問我,道長赊淑,這世上最難降的妖魔是什么爵政? 我笑而不...
    開封第一講書人閱讀 56,648評論 1 284
  • 正文 為了忘掉前任,我火速辦了婚禮陶缺,結(jié)果婚禮上钾挟,老公的妹妹穿的比我還像新娘。我一直安慰自己饱岸,他們只是感情好掺出,可當我...
    茶點故事閱讀 65,770評論 6 386
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著苫费,像睡著了一般汤锨。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上百框,一...
    開封第一講書人閱讀 49,950評論 1 291
  • 那天泥畅,我揣著相機與錄音,去河邊找鬼。 笑死位仁,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的方椎。 我是一名探鬼主播聂抢,決...
    沈念sama閱讀 39,090評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼棠众!你這毒婦竟也來了琳疏?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,817評論 0 268
  • 序言:老撾萬榮一對情侶失蹤闸拿,失蹤者是張志新(化名)和其女友劉穎空盼,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體新荤,經(jīng)...
    沈念sama閱讀 44,275評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡揽趾,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,592評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了苛骨。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片篱瞎。...
    茶點故事閱讀 38,724評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖痒芝,靈堂內(nèi)的尸體忽然破棺而出俐筋,到底是詐尸還是另有隱情,我是刑警寧澤严衬,帶...
    沈念sama閱讀 34,409評論 4 333
  • 正文 年R本政府宣布澄者,位于F島的核電站,受9級特大地震影響请琳,放射性物質(zhì)發(fā)生泄漏粱挡。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 40,052評論 3 316
  • 文/蒙蒙 一单起、第九天 我趴在偏房一處隱蔽的房頂上張望抱怔。 院中可真熱鬧,春花似錦嘀倒、人聲如沸屈留。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,815評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽灌危。三九已至,卻和暖如春碳胳,著一層夾襖步出監(jiān)牢的瞬間勇蝙,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,043評論 1 266
  • 我被黑心中介騙來泰國打工挨约, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留味混,地道東北人产雹。 一個月前我還...
    沈念sama閱讀 46,503評論 2 361
  • 正文 我出身青樓,卻偏偏與公主長得像翁锡,于是被迫代替她去往敵國和親蔓挖。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 43,627評論 2 350

推薦閱讀更多精彩內(nèi)容

  • 1說說JVM垃圾回收機制馆衔。 http://blog.csdn.net/xiajian2010/article/de...
    Alfred泉閱讀 757評論 0 2
  • 本系列出于AWeiLoveAndroid的分享瘟判,在此感謝,再結(jié)合自身經(jīng)驗查漏補缺角溃,完善答案拷获。以成系統(tǒng)。 Java基...
    濟公大將閱讀 1,524評論 1 6
  • 0參考代碼 藍牙(BLE)模塊及協(xié)議.pdf:在電腦內(nèi)减细,有助于理解ble BLE藍牙在Android開發(fā)中的應(yīng)用 ...
    kamin閱讀 3,432評論 0 20
  • 過來人表示,真的會树埠。 我和媳婦當年是同事糠馆,典型的辦公室戀情,同時怎憋,由于我們都是本地人又碌,上班在一起,下班膩一會绊袋,基本...
    迷糊的圖圖醬閱讀 426評論 2 1
  • 我想說一下遠方學什么毕匀? 何為遠方 1、首先課程分為五級癌别,預(yù)備級是趣味史地文化皂岔。 第一級是中國古代文學知識。 第二級...
    花開遠方樊老師閱讀 286評論 0 1