在 Android 开发中经常使用到的小功能,用于记录开发的那些事^_^

1. 获取 release 和 debug 版本的 SHA1

public static String getSHA1(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
context.getPackageName(), PackageManager.GET_SIGNATURES);
byte[] cert = info.signatures[0].toByteArray();
MessageDigest md = MessageDigest.getInstance("SHA1");
byte[] publicKey = md.digest(cert);
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < publicKey.length; i++) {
String appendString = Integer.toHexString(0xFF & publicKey[i])
.toUpperCase(Locale.US);
if (appendString.length() == 1)
hexString.append("0");
hexString.append(appendString);
hexString.append(":");
}
String result = hexString.toString();
return result.substring(0, result.length()-1);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}

2. 打开 APP 华为手机提示全屏显示

  在 AndroidManifest.xml 中的 Application 节点下添加如下代码:

<meta-data android:name="android.max_aspect" android:value="2.4" />

3. 保持屏幕常亮

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

通常会在一个 Activity 的 onResume() 和 onPause() 方法中分别调用这两个方法。

4. ListView 动态设置数据时高度自适应

package com.custom.ui.view;

import android.content.Context;
import android.widget.ListView; public class MyListView extends ListView { public MyListView(Context context) {
super(context);
} @Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int mExpandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, mExpandSpec);
} }
<com.custom.ui.view.MyListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:divider="@null"
android:listSelector="@color/transparent"/>

5. 防止 ListView 动态设置数据时数据过长自动滑动至 ListView 底部

android:descendantFocusability="blocksDescendants"

该属性是当一个为view获取焦点时,定义 ViewGroup 和其子控件两者之间的关系。
属性的值有三种:
beforeDescendants:ViewGroup 会优先其子类控件而获取到焦点
afterDescendants:ViewGroup 只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:ViewGroup 会覆盖子类控件而直接获得焦点

6. Android 强大的工具类推荐

https://blankj.com/2016/07/31/android-utils-code/

Android 开发常用工具合集的更多相关文章

  1. 老李分享:android app自动化测试工具合集

    老李分享:android app自动化测试工具合集   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨 ...

  2. Android开发常用工具汇总

    Android开发常用工具汇总,本文章不断更新完善 一.数据库小工具Sqlite Developer  SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它的设计目标是嵌入式的, ...

  3. Android开发常用工具类

    来源于http://www.open-open.com/lib/view/open1416535785398.html 主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java. 目前 ...

  4. 最全Android开发常用工具类

    主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java. 目前包括  HttpUtils.DownloadManagerPro.Safe.ijiami.ShellUtils.Pack ...

  5. C# 常用工具合集

    Visual Studio 2013 扩展 Visual Studio 2013 Update 4:是目前微软发布的最新版开发工具升级包,高效而且强大.下面的扩展都是该版本的Visual Studio ...

  6. android 开发 常用工具类

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38965311,本文出自[张鸿洋的博客] 打开大家手上的项目,基本都会有一大批的辅 ...

  7. 转发—Android开发常用的插件及工具

    作者:蓝之风 出处:http://www.cnblogs.com/vaiyanzi/ Android开发常用的插件及工具 1.GitHub,这个不管是做安卓还是其他,只要是开发就必上的网站,也是天朝没 ...

  8. 【转】Ubuntu常用软件合集

    [转]Ubuntu常用软件合集 Ubuntu常用软件合集 我用的使Ubuntu-Kylin14.04,原因呢主要是觉得使本土化的,自带了日历.输入法.优客助手等易于上手的应用.也省的每次安装完原生的系 ...

  9. es6常用基础合集

    es6常用基础合集 在实际开发中,ES6已经非常普及了.掌握ES6的知识变成了一种必须.尽管我们在使用时仍然需要经过babel编译. ES6彻底改变了前端的编码风格,可以说对于前端的影响非常巨大.值得 ...

随机推荐

  1. Python——Python安装

    下载地址:https://www.python.org/downloads/windows/ 3.X安装方法: 1. 设置一个自选路径,并将下面的选项打钩.(建议使用根目录) 2. 应用在所有用户中 ...

  2. SQL SERVER-CROSS APPLY

    CROSS APPLY和 OUTER APPLY 区别详解 SQL Server 2005 新增 cross apply 和 outer apply 联接语句,增加这两个东东有啥作用呢? 我们知道有个 ...

  3. uwsgi配置文件示例

    uwsgi配置文件参考 相关路径请根据自己项目的实际路径配置 在进行Nginx+uwsgi部署Django项目的时候,需要Nginx的配置中包含uwsgi的配置项,具体请查看另一篇:Nginx配置文件 ...

  4. 智能驾驶数据后处理分析利器—INTEWORK-VDA

            随着智能驾驶技术在新车上逐步普及,车辆研发阶段需要做大量的实车测试工作,当前的测试方式主要是路采实车数据后,按标准和法规进行测试场景提取和测试数据分析.调查显示绝大部分智能驾驶研发厂商 ...

  5. Vue移动组件库Mint UI的安装与使用

    一.什么是 Mint UI 1.Mint UI 包含丰富的 CSS 和 JS 组件,可以提升移动端开发效率 2.Mint UI 按需加载组件 3.Mint UI 轻量化 二.Mint UI 的安装 1 ...

  6. WIN10笔记本屏幕亮度无法调节,一直是最高亮度

    WIN+X,选择"计算机管理"; 系统工具->设备管理器->找到右边的"显示适配器"->右键先禁用,再启动下图设备

  7. AngularJs中Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/

    我在使用angularjs的时候报出来这个错误: Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/ 当时 ...

  8. oracle中日期相关的区间

    and czrqb.lsrqb_rh_sj >= to_date('[?query_date_begin|2011-09-01?]A', 'yyyy-mm-dd') and czrqb.lsrq ...

  9. idea Mapper.java中快速生成@Param注解

    1.鼠标悬浮到方法后 2.Ctrl+Enter打开操作列表 3.选择[Mybatis] Generate @Param自动生成@Param() 4.说明:@Param("参数名") ...

  10. 使用notepad++/excle快速将cvs文件转换为insert语句技巧以及注意点

    使用notepad++/excle快速将cvs文件转换为insert语句技巧以及注意点 业务场景 最近nc项目经理从第三方弄来了一个300w行的csv文件,让导入数据库做处理,出现了下列问题: csv ...