安卓一些常用的小知识

1、android gradle 3.0.0 中依赖指令implementation、api 的区别。

  • 简单来说就是使用implementation指令的依赖不会传递。例如,有一个module为sdk,sdk依赖于gson库,有另一个module为test依赖于sdk,但是test不能直接引用到gson这个库,而api则可以做到。但是api既然有这优势必然有其劣势,那就是编译会比implementation慢,所以能用implementation就用这个,迫不得已再用api。

2、在Google最新推出的Meterial Design中可以说用RecyclerView代替了ListView,而NestedScrollView代替了ScrollView。他们两个都可以用来跟ToolBar交互,实现上拉下滑中ToolBar的变化。在NestedScrollView的名字中其实就可以看出他的作用了,Nested是嵌套的意思,而ToolBar基本需要嵌套使用。所以一般只要稍微复杂点的场景建议使用RecyclerView与NestedScrollView。

3、应用图标应该放在mipmap目录下,其它图片资源应该放在drawable目录下。具体可以看看官方文档解释:https://developer.android.google.cn/guide/topics/resources/providing-resources

4、接口实现备注是实现哪个接口通过@link来做,会比较清楚。

public final class VerfiyEditText extends EditText
        implements View.OnTouchListener,
        View.OnFocusChangeListener, TextWatcher {

    public PasswordEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setOnTouchListener(this);
        setOnFocusChangeListener(this);
        addTextChangedListener(this);
    }

    /**
     * {@link OnFocusChangeListener}
     */

    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        ......
    }

    /**
     * {@link OnTouchListener}
     */

    @Override
    public boolean onTouch(View view, MotionEvent event) {
        ......
    }

    /**
     * {@link TextWatcher}
     */

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        ......
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        ......
    }

    @Override
    public void afterTextChanged(Editable s) {
        ......
    }
}

5、第三方框架使用规范

集成一些第三方框架或者 SDK,必须注明作用和出处,以便出现问题时能够快速核查和反馈


// 权限请求框架:https://github.com/sc/XXPermissions
implementation 'com.sc:xxpermissions:9.8'
上一篇:android项目app中引用不到module下的jar包问题


下一篇:ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the clas