Android项目100项

作者: Small_Cake | 来源:发表于2020-02-03 15:34 被阅读0次

    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.方法数超过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的关联

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

    6.设置去掉所有的页面标题栏

    在AppTheme中配置

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

    7.快速构建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里,一次性加载出全部数据问题
    https://github.com/CymChad/BaseRecyclerViewAdapterHelper/issues/1954
    Android SwipeRefreshLayout和RecyclerView嵌套时 下拉刷新冲突的解决办法
    https://blog.csdn.net/peirato_/article/details/54913195

    针对RecyclerView不显示

    只需要设置ScrollView的属性android:layout_height="match_parent" android:fillViewport="true" 就OK了。

    • 监听RecyclerView滚动距离
     //RecyclerView滚动监听
            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://现在不是滚动状态
                            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网络请求,生成

     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);
    

    代码中绘制左侧图片

    Drawable img = layout.getResources().getDrawable(R.drawable.icon);  
    // 调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示  
    img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight());  
    textView.setCompoundDrawables(img, null, null, null); //设置左图标  
    

    文字滚动消息:

     < 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 ="那么什么是成功的人生,什么样的人又是成功人士呢?像科技界的比尔?盖茨 ,乔布斯 ,商界的巴菲特以及娱乐、体育界的大腕,无疑会被人们视为是成功者。但对于普通民众,如果用比尔?盖茨那样的标准来衡量是否成功似乎有些太苛刻,也不现实。在某种观念中,一个人的成功似乎与财富分不开的。很多国人到美国看到华人最常说的一句话是,你是个成功人士。为什么这么说?因为你能住300平方米、价值百万美元的房子,因为你开的车是奔驰 、宝马等豪华车,因为你有好的工作,年薪至少在10万美元以上。这也许是很多国人看待一个人成功与否的主要标志。但在美国人眼里,成功并不是与拥有众多财富密不可分。在1980年代,多数美国人把拥有更多财富看成人生成功的一个主要标志。而在一项最新的调查中,对于美国人来说,财富不再是成功的最重要组成部分。调查中22个成功人生的潜在组成因素中,“有很多钱”仅排名在第20位。" />
    

    12.对Retrofit回调进行封装,只输出正确和错误信息

    自定义Retrofit网络回调结果

    13.EditText变搜索按钮,并监听搜索事件

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

    14.CoordinatorLayout布局要设置滚动控件的

    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    

    里面的字符串爆红,但还是可以运行,但红色总是不好看的,可能是新版本的sdk引起的,所以需要改为

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

    15.WebView不跳转到外部浏览器

    class MyWebViewClient extends WebViewClient{
            //不跳转到外部浏览器
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        }
    

    Android webview loadData 中文乱码
    https://www.jianshu.com/p/85957f003dd4

    16.WebView出现net::ERR_UNKNOWN_URL_SCHEME错误

    https://www.jianshu.com/p/119823e5cfb5

    17.Glide显示图片为上面圆角,下面直角

    让Glide输出指定位置的圆角图片 2018年,部分方法为Glide4.0以前的,所以无法使用,但方法值得借鉴
    Glide 加载部分圆角图片2019年,新的方法,且行为更合理
    圆角不圆:有可能是因为图片高度或宽度过大,导致部分圆角不圆
    Glide ViewTarget及SimpleTarget加载问题:

    18.View转换为Bitmap

    关于View转化成bitmap保存成图片
    两个Bitmap合并为一个
    Android:将一个Activity、某块布局转换成图片

    19.使用xml绘制虚线好后,4.0以上需要使用 android:layerType="software"属性,不然虚线会变为实线

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

    20.微信分享到朋友圈,调用系统分享,需要对Uri单独处理一下

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

    21.support版本冲突的解决办法

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

    22.TabLayout+ViewPager垂直方向联动,用于分类页面

    https://www.jianshu.com/p/9266e58cc4f5

    23.精确计算RecyclerView滑动高度

    SlideRecyclerView

    24.adb无线调试

    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是否已经签名:
    https://blog.csdn.net/qq_21376985/article/details/53337977

    27.混淆

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

    28.TextView设置可滚动的方式

    xml中设置TextView属性

    android:scrollbars="vertical"
    

    同时代码中设置

     textView.setMovementMethod(ScrollingMovementMethod.getInstance());
    

    29.Android:通过Glide保存图片到本地,并同步到相册

    30.Android 调用系统分享(不使用第三方),指定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控件的高度,通过监听的方式

    https://www.jianshu.com/p/2c8e5324ec68

    你可能也不知道为什么,第一次进入页面,获取控件的高度有值,再次进入获取的高度居然为0,再再再次进入也为0,杀掉应用,进入页面又有高度了,再次进入又为0。因为我需要通过view来获取Bitmap,那么View的宽高值必不可少,所以我通过上面博客的方法去监听控件的高度才拿到值。但为什么只有第一次进入才能拿到宽高值却拜师不得琪姐,请各位大老解答。

    33.AccessibilityService获取控件信息getRootInActiveWindow() 经常为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.新手引导库

    GuideView

    在Fragment中由于控件位置绘制流程和生命周期的关系,需要监听控件View宽高,有值后才进行引导层的绘制,同时用Handler进行一定的延迟绘制,保证高亮区域的定位精确度

    35.Java中对对象进行排序

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

    通过Comparable

    36.监控当前APP是否回到前台

    https://www.jianshu.com/p/101eb42d0fde

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

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

    38.Fragment的优化

    不要再Activity中使用List来保存Fragment
    https://blog.csdn.net/qq_30993595/article/details/80736814

    39.ViewPager2,支持横竖布局,支持0预加载布局

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

    40.RadioGroup.onCheckedChanged() 会调用多次

    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.对时间的转换,对比,添加,格式输出

    joda-time

    45. tools:replace的使用

    tools:replace=""有时候需要替换多个项,使用逗号分割
    tools:replace="android:allowBackup,android:appComponentFactory"

    46. 解决 导入三方时出现: appComponentFactory 错误

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

    47. 滚轮时间选择器

    可以采用 XPopupWheelPicker
    组合的方式来生成一个时间选择器如:https://www.jianshu.com/p/4a2c853d9276

    48. fragment里coordinatorlayout+viewpager无法正常滑动问题

    fragment里coordinatorlayout+viewpager无法正常滑动问题
    有人说fragment是无法运行协调者布局的,这是错误的
    解决方法:在你的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.数据绑定DataBind

    android {
        …
        dataBinding {
            enabled = true
        }
    }
    

    告别findView和ButterKnife
    Android开发教程 - 使用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需要设置渠道和权重

    https://www.jianshu.com/p/f85ef58edf63

    58.uri指向了外部应用exposed beyond app through RemoteViews.setUri()

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

    StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
            builder.detectFileUriExposure();
    

    59.解决因为弹窗导致TextView停止滚动的问题:

    https://www.jianshu.com/p/22b4aff0dc8e

    60.弹窗需要一个自定义的三角形SanJiaoView

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

    61.升级AndroidX后出现缺失AppBarLayout$ScrollingViewBehavior

    https://www.jianshu.com/p/6b8104787617

    62.APP启动时间,性能优化,启动页白屏

    https://www.jianshu.com/p/75b0b128c470

    63.AndroidStudio安装失败

    image.png

    方法一:clean项目
    方法二:重启大法:重启AndroidStudio,重启手机,重启电脑,重启...
    方法三:检查是否只开启了开发者模式和USB调试,却没有开启了USB安装


    image.png

    64.adb命令

    https://www.jianshu.com/p/56fd03f1aaae

    65.ConstraintLayout基础 及动态控件(动画效果)

    https://www.jianshu.com/p/7888cde8292f

    66.获取videoView第一针视频报错:

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

    67.Math函数相关计算

    //角度换算为对应数值
    double skewRot = Math.toRadians(30);

    68. banner库一张图片无效和第一次进入没有轮播的时候点击第一张无效

    一张图片的时候需要设置banneronClick事件,多张图第一次还未开始轮播点击无效,需要先设置点击事件,再调用bannerstart方法

    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("发生崩溃=="+thread.getName()+"  =="+ex.getMessage());
                }
            });
    

    72.Android Q正式发布。新一代的安卓系统非常注重对用户隐私的保护,它限制APP获取IMEI、DEVICE ID等移动端设备标识码,解决方案:

    简书:https://www.jianshu.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秒时,退出应用
                    } else {
                        System.exit(0);
                    }
                    break;
            }
            return super.onKeyUp(keyCode, event);
        }
    

    如果是Fragment请不要复写onBackPressed()方法,改为复写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升级日记

    https://www.jianshu.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.简单实现ImageView宽度填满屏幕,高度自适应的两种方式

    https://www.jianshu.com/p/c9424615e99d

    77.RecyclerView瀑布流问题

    https://www.jianshu.com/p/4e142909b824
    https://blog.csdn.net/tobevan/article/details/78924338

    78.android studio关闭字符串资源多语言提示

    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获取内网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服务
            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获取外网IP

    参考:https://www.jianshu.com/p/1e3eaf887191

    方法一,通过访问第三方接口地址来获取

    import org.json.JSONException;
    import org.json.JSONObject;
     /**
         * 获取外网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();
                            // 从反馈的结果中提取出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架构7种

    参考:https://blog.csdn.net/u012400885/article/details/52923765
    https://www.jianshu.com/p/f29ad4beef59

    86.'gradle' 不是内部或外部命令,也不是可运行的程序 或批处理文件

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

    87.使用ImmersionBar时,加载出现Dialog的显示会导致导航栏出现不消失:

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

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

    89.删除git配置

    删除

    90.把本地项目复制到github

    分享

    91.AndroidStudio设置github账号

    image.png

    92.邀请码识别来源

    https://www.openinstall.io/

    93.Android 自动抓取网站图标实现分享样式的定制

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

    94.Fragment实现懒加载

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

    95.版权登记

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

    96.获取随机颜色值

    分别取rgb的随机值(0~256),然后加起来就是一个随机颜色值,通过Color.parseColor()转为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;
        }
    

    97.Glide设置圆角图片后设置ImageVIew的scanType="centerCrop"无效解决办法

    https://www.jianshu.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);
    

    98.线性渐变字体

    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);
        }
    }
    

    99.TextView 设置其他字体后,显示不全的问题

    https://blog.csdn.net/u010979599/article/details/86650297
    https://www.jianshu.com/p/4314cc68c1f3

    100.Android视频播放,选择,压缩,上传

    https://www.jianshu.com/p/78b7176c041e

    相关文章

      网友评论

        本文标题:Android项目100项

        本文链接:https://www.haomeiwen.com/subject/zzptgqtx.html