常用到的小知识点

记录一些自己收集的小知识点。

1、Android Studio 获取发布版和测试版证书SHA1的两种方式

参考文档:
https://my.oschina.net/djonce/blog/761372

第一种:

1)项目界面右侧,点击“Gradle”
2)之后找到如下图中红框中的signingReport选项双击(如果没有出现应用程序名称,可点击刷新按钮):

3)在信息框中将会显示开发版和发布版的安全码(MD5和SHA1),其中默认的版本是debug,如下图。

第二种(根据命令的方式获取):

1)在Android Studio中的底栏找到 Terminal 打开,输入命令行:keytool -list -v -keystore C:\Users\xmg.android\debug.keystore (这里输入你自己电脑 debug.keystore 的路径)。

输入秘钥库口令(默认是空,如果自己当初设置过了就输入自己设置的密码):

2、Android自定义属性,attr format取值类型

  1. reference:参考某一资源ID。
  2. reference:参考某一资源ID。

(1)属性定义:

<declare-styleable name = "名称">    
<attr name = "background" format = "reference" />    
</declare-styleable>

(2)属性使用:

<ImageView
    android:layout_width = "42dip" 
    android:layout_height = "42dip" 
    android:background = "@drawable/图片ID"/>
  1. color:颜色值。

(1)属性定义:

<declare-styleable name = "名称">
    <attr name = "textColor" format = "color" />
</declare-styleable>

(2)属性使用:

<TextView
    android:layout_width = "42dip" 
    android:layout_height = "42dip" 
    android:textColor = "#00FF00"/>
  1. boolean:布尔值。

(1)属性定义:

<declare-styleable name = "名称">
    <attr name = "focusable" format = "boolean" />
</declare-styleable>

(2)属性使用:

<Button
    android:layout_width = "42dip" 
    android:layout_height = "42dip"
    android:focusable = "true"/>
  1. dimension:尺寸值。

(1)属性定义:

<declare-styleable name = "名称">
    <attr name = "layout_width" format = "dimension" />
</declare-styleable>

(2)属性使用:

<Button
    android:layout_width = "42dip" 
    android:layout_height = "42dip"/>
  1. float:浮点值。

(1)属性定义:

<declare-styleable name = "AlphaAnimation"> 
    <attr name = "fromAlpha" format = "float" /> 
    <attr name = "toAlpha" format = "float" />  
</declare-styleable>    

(2)属性使用:

<alpha 
    android:fromAlpha = "1.0" 
    android:toAlpha = "0.7"/>
  1. integer:整型值。

(1)属性定义:

<declare-styleable name = "AnimatedRotateDrawable">
    <attr name = "visible" /> 
    <attr name = "frameDuration" format="integer" /> 
    <attr name = "framesCount" format="integer" /> 
    <attr name = "pivotX" /> 
    <attr name = "pivotY" /> 
    <attr name = "drawable" />
</declare-styleable>

(2)属性使用:

<animated-rotate
    xmlns:android ="http://schemas.android.com/apk/res/android" 
    android:drawable = "@drawable/图片ID" 
    android:pivotX = "50%" 
    android:pivotY = "50%" 
    android:framesCount = "12" 
  1. string:字符串。

(1)属性定义:

<declare-styleable name = "MapView"> 
    <attr name = "apiKey" format = "string" /> 
</declare-styleable>

(2)属性使用:

<com.google.android.maps.MapView 
    android:layout_width = "fill_parent" 
    android:layout_height = "fill_parent" 
    android:apiKey ="0jOkQ80oD1JL9C6HAja99uGXCRiS2CGjKO_bc_g"/>
  1. fraction:百分数。

(1)属性定义:

<declare-styleable name="RotateDrawable"> 
    <attr name = "visible" /> 
    <attr name = "fromDegrees" format = "float" /> 
    <attr name = "toDegrees" format = "float" /> 
    <attr name = "pivotX" format = "fraction" /> 
    <attr name = "pivotY" format = "fraction" /> 
    <attr name = "drawable" /> 
</declare-styleable>

(2)属性使用:

<rotate
    xmlns:android ="http://schemas.android.com/apk/res/android" 
    android:interpolator = "@anim/动画ID"
    android:fromDegrees = "0" 
    android:toDegrees = "360"
    android:pivotX = "200%"
    android:pivotY = "300%" 
    android:duration = "5000"
    android:repeatMode = "restart"
    android:repeatCount = "infinite"/>
  1. enum:枚举值。

(1)属性定义:

<declare-styleable name="名称"> 
    <attr name="orientation"> 
    <enum name="horizontal" value="0" /> 
    <enum name="vertical" value="1" /> 
    </attr>
</declare-styleable>

(2)属性使用:

<LinearLayout
    xmlns:android = "http://schemas.android.com/apk/res/android" 
    android:orientation = "vertical" 
    android:layout_width = "fill_parent" 
    android:layout_height = "fill_parent" > 
</LinearLayout>
  1. flag:位或运算。

(1)属性定义:

<declare-styleable name="名称"> 
    <attr name="windowSoftInputMode"> 
        <flag name = "stateUnspecified" value = "0" /> 
        <flag name = "stateUnchanged" value = "1" /> 
        <flag name = "stateHidden" value = "2" /> 
        <flag name = "stateAlwaysHidden" value = "3" /> 
        <flag name = "stateVisible" value = "4" /> 
        <flag name = "stateAlwaysVisible" value = "5" /> 
        <flag name = "adjustUnspecified" value = "0x00" /> 
        <flag name = "adjustResize" value = "0x10" /> 
        <flag name = "adjustPan" value = "0x20" /> 
        <flag name = "adjustNothing" value = "0x30" /> 
    </attr>     
</declare-styleable>

(2)属性使用:

<activity
    android:name = ".StyleAndThemeActivity" 
    android:label = "@string/app_name" 
    android:windowSoftInputMode = "stateUnspecified | stateUnchanged | stateHidden"> 
    <intent-filter> 
        <action android:name = "android.intent.action.MAIN" /> 
        <category android:name = "android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity>        

注意:属性定义时可以指定多种类型值。

(1)属性定义:

<declare-styleable name = "名称">    
    <attr name = "background" format = "reference|color" />    
</declare-styleable>

(2)属性使用:

<ImageView
    android:layout_width = "42dip" 
    android:layout_height = "42dip" 
    android:background = "@drawable/图片ID|#00FF00"/>

3、Butterknife的一些注意地方

Butterknife官方文档 GitHub:

https://github.com/JakeWharton/butterknife

(1)Butterknife:8.x.x后运行导致的空指针问题

Butterknife:8.x.x相对于原来的Butterknife:7.1.0来说,使用起来更方便,效率上也有一定的提升,但是在使用的过程中要注意: Butterknife:8.x.x之后引用了“android-apt”这个插件,我们在使用的过程中也必须引用,否则在调用其注解下的View时会报空指针异常。 解决办法:

1、第一步

buildscript {
    repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

2、第二步

apply plugin: 'android-apt' 
android {
 ...
}

dependencies {
    compile 'com.jakewharton:butterknife:8.x.x'
    apt 'com.jakewharton:butterknife-compiler:8.x.x'
}

提示:如果不引用android-apt也能使用,但是会有异常。

使用butterknife需要在ID上右击或者alt+insert才能出来生成选项。其它地方无效

(2)android-apt是什么?

参考文档:
http://www.jianshu.com/p/2494825183c5#

4、翻译插件 ECTranslation

Setting–>plugins–>ECTranslation 安装—>重启as

使用方法:选中要翻译的英文,菜单栏Edit–Translate

自定义快捷键:Settings -> Keymap -> 搜索Translate - > 右键 add Keyboard Shortcut. 输入你想要的快捷键即可

5、 在使用android studio 时发现 adb 无法正常使用。

解决方法:

1、输入netstat -ano | findstr "5037"

2、tasklist| findstr "xxx" 查看占用程序

3、查看端口是否被占用 ,打开任务管理器-》查看——》选择列-》勾选pid,在任务栏中找到 相应的端口进程结束 

6、Execution failed for task:app:transformResourcesWithMergeJavaResForDebug;

参考文档:http://www.2cto.com/kf/201601/487909.html

解决方法:

build.gradle文件中加入:

 packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
 }

完整代码部分:

apply plugin: 'com.android.application' 
android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    defaultConfig {
        applicationId "com.oyp.csdn"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

7、 C:\Users\Administrator>adb start-server adb server version (32) doesn’t match this client (36); killing…* daemon started successfully * C:\Users\Administrator>adb nodaemon server error: could not install smartsocket listener: cannot bind to 127.0.0.1:5037: 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 (10048)

报错原因:

是和genymotion冲突了,在genymotion的设置->ADB里面,选择本地的sdk目录就可以了

8、android studio 查看23版源码错误

参考文档:
http://www.cnblogs.com/kingxiaozi/p/5599988.html

解决步骤:

1)找到C盘下androidStuodio的配置,我的是2.2版本下的 jdk.table.xml

2)修改文件内容
    <root type="simple" url="file://D:/android/sdk/docs/reference" />
改为:
    <root type="simple" url="file://D:/android/sdk/source/android-23" />

3)重启AndroidStudio,问题解决
9、在Android Studio中新建Activity默认继承AppCompatActivity,在Android Studio安装目录下有个模板文件,修改其中的参数即可。common_globals.xml.ftl

路径如下:(自己的AS安装路径)
E:AS\android-studio-2.0\plugins\android\lib\templates\activities\common

部分代码如下,在文件中搜索如下关键字 appCompatActivity。用第一个数据替代第二个对应的value

<#if !appCompat>
    <global id="superClass" type="string" value="Activity"/>
    <global id="superClassFqcn" type="string" value="android.app.Activity"/>
    <global id="Support" value="" />
    <global id="actionBarClassFqcn" type = "string" value="android.app.ActionBar" />

<#elseif appCompatActivity>
    <global id="superClass" type="string" value="AppCompatActivity"/>
    <global id="superClassFqcn" type="string" value="android.support.v7.app.AppCompatActivity"/>
    <global id="Support" value="Support" />
    <global id="actionBarClassFqcn" type = "string" value="android.support.v7.app.ActionBar" />

<#else>
    <global id="superClass" type="string" value="ActionBarActivity"/>
    <global id="superClassFqcn" type="string" value="android.support.v7.app.ActionBarActivity"/>
    <global id="Support" value="Support" />
    <global id="actionBarClassFqcn" type = "string" value="android.support.v7.app.ActionBar" />
10、怎么解决Android studio导入项目卡死

(1)打开项目/gradle/wrapper找到这个文件: gradle-wrapper.properties ,

distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip

将上面那个文件的版本改成你自己那个目录有的版本。

(2)打开项目目录下的build.gradle打开发现:

dependencies{
        classpath 'com.android.tools.build:gradle:2.2.3'
    }

将上面那个文件的版本改成你自己有的版本。再打开项目即可。

一些有用的知识点,框架网址收集

Android 详细分析AppBarLayout的五种ScrollFlags
http://www.jianshu.com/p/7caa5f4f49bd

深入理解LayoutInflater.inflate()
http://www.jianshu.com/p/41796f541e67

Android 屏幕适配:最全面的解决方案
http://www.jianshu.com/p/ec5a1a30694b

拥抱SVG:苦恼于图片适配 in Android?万能图片适配
http://mp.weixin.qq.com/s?__biz=MzI0MjE3OTYwMg==&mid=2649548366&idx=1&sn=6cbdf8652ec139859d9be01444e1ad3b&chksm=f1180d33c66f8425a286de4fd5f03aa89308add3593529a91356439cb8c2f8542305561034c8&scene=21#wechat_redirect

2016,你最不应该错过的热门技术文章
http://tech.meituan.com/all_the_papers_2016.html

RxJava 学习
https://github.com/lzyzsd/Awesome-RxJava

2016 年度码云新增热门开源软件排行榜 TOP 50
https://www.oschina.net/news/81027/2016-oschina-git-new-software-top-50

自定义可折叠按钮
http://blog.csdn.net/vroymond/article/details/76472551

CoordinatorLayout 自定义Behavior并不难,由简到难手把手带你撸三款!
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0824/6565.html

移动热修复
https://www.aliyun.com/product/hotfix

Android 热修复专题:支付宝、淘宝、微信、QQ空间、饿了么、美丽说蘑菇街、美团大众点评方案集合
https://zhuanlan.zhihu.com/p/25863920

Android安全开发之浅谈密钥硬编码
http://jaq.alibaba.com/community/art/show?spm=a313e.7916648.0.0.iEV6Rk&articleid=321

Android开发设计模式系列
http://mobile.51cto.com/android-419145.htm

android直播开发
http://blog.csdn.net/column/details/kklive8.html

Firebase
https://firebase.google.cn

安利一波androidView视觉开源控件 每个都值得学习哦【简单说】
http://www.jianshu.com/p/30909296ac01

想写个App练手,有什么有趣的API接口推荐吗?
https://github.com/jokermonn/-Api
https://github.com/toddmotto/public-apis

74款APP完整源码!
http://www.jianshu.com/p/b6c25e88786d

2017年,身为Android开发的你必须要掌握的热门开源框架
https://mp.weixin.qq.com/s?__biz=MzI0MjE3OTYwMg==&mid=2649548737&idx=1&sn=07e77f55fc2cbd575322b151e0a0b648&chksm=f1180cbcc66f85aa8244c17b67d9fc16388c0eb36e9c0ec6c8fcd259ced220ca0fb142a31876&scene=21#wechat_redirect

2017年Android百大框架排行榜
https://mp.weixin.qq.com/s?__biz=MzAxMTI4MTkwNQ==&mid=2650823358&idx=1&sn=945e089df1adae9781a725b4c9bf39d9&chksm=80b78e20b7c007367fe1e7c9aa70c49d8b57dbd5007f143336f90c0ae26206b93f64799031f1&mpshare=1&scene=1&srcid=0628zt2Ym3esD6NqQT19AsZw#rd

2017 Android GitHub常用开源框架汇总
http://mobile.51cto.com/android-546316.htm

GitHub上最火的Android开源项目,所有开源项目都有详细资料和配套视频
https://github.com/open-android/Android

Android经久不衰最受欢迎的开源库整理
http://www.jianshu.com/p/fb87365f4086

Android开发常用开源框架
https://jackchan1999.github.io/2017/05/01/open/%E5%BC%80%E6%BA%90%E6%A1%86%E6%9E%B6/

2017已来,最全面试总结——这些Android面试题你一定需要
http://mp.weixin.qq.com/s?__biz=MzI0MjE3OTYwMg==&mid=2649548612&idx=1&sn=8e46b6dd47bd8577a5f7098aa0889098&chksm=f1180c39c66f852fd955a29a9cb4ffa9dc4d528cab524059bcabaf37954fa3f04bc52c41dae8&scene=21#wechat_redirect

Android 源码、面试大全:
http://www.iteye.com/topic/1142381

2017常见android面试题
http://www.jianshu.com/p/afc54b7e90cb

Android 开发面试 “108” 问
https://xiaozhuanlan.com/topic/1570489362

http://blog.csdn.net/u012987546?viewmode=contents

http://blog.csdn.net/guolin_blog

http://www.android-doc.com/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值