Android Studio 一些注意事项(自用,不定期更新)

1,Android Studio 版本的选择

写这篇的时候,官方版本已经到了 v3.2.0,而我习惯使用的版本是 v2.3.1,因为这个版本有自带sdk的安装版,比较方便,

同时,v2.3.1 新建项目是用的Gradle v3.3 版本

2,各种东西的版本问题

AS相较于Eclipse而言,AS最恶心的东西莫过于各种东西的版本号对应关系,错一点儿都各种异常,v2.3.1的一些默认版本信息:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.sungong1987.helloandroid"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    testCompile 'junit:junit:4.12'
}
build.gradle

为什么要记录这个呢?因为有些时候,莫名其妙的新建出来的gradle文件会有问题,要把这几个版本的数字该成默认的项目才会成功

3,关于menu

这个版本新建项目时是没有menu资源的,新建如下:

首先,res → 右键 → New → Android resources directory → Resource type → menu,然后就在res里添加了一个menu文件夹

然后,在刚建立的 menu → 右键 → New → Menu resource file

4,关于 menu.xml 的 showAsAction 属性的特殊说明

因为版本的问题,所以注意如下配置:

xmlns:app="http://schemas.android.com/apk/res-auto"
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/action_add"
        app:showAsAction="ifRoom|withText"
        android:title="@string/action_add" />

    <item
        android:id="@+id/action_del"
        app:showAsAction="never"
        android:orderInCategory="99"
        android:title="@string/action_del" />

    <item
        android:id="@+id/action_set"
        app:showAsAction="never"
        android:orderInCategory="100"
        android:title="@string/action_set"/>

</menu>
menu.xml

sdk4.2之后如下设置

在代码中:

以上图片转自 https://blog.csdn.net/rosener/article/details/52638492

always:总是显示在界面上
never:不显示在界面上,只让出现在右边的三个点中
ifRoom:如果有位置才显示,不然就出现在右边的三个点中

5,Android 中 tools:ignore="UselessParent" 这个属性的含义

这个属性是给lint检查工具看的,这个告诉IDE 以避免显示这样一条消息: "此 RelativeLayout 布局或其 LinearLayout 父是无用"

6,android:orderInCategory="100" 属性说明

设置优先级,值越大优先级越低

7,LayoutInflater中inflate方法两个参数和三个参数的区别

https://blog.csdn.net/u012702547/article/details/52628453

posted @ 2018-10-15 15:46  孙公  阅读(399)  评论(0编辑  收藏  举报