记录安卓开发中的问题

4、

java代码动态添加组件,xml负责布局

        LinearLayout layout_pgm = findViewById(R.id.layout_pgm);
        AdvancedBtn btn_pgm = new AdvancedBtn(this);

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        btn_pgm.setLayoutParams(layoutParams);

        btn_pgm.setGravity(Gravity.CENTER);
        btn_pgm.setText(R.string.PGM);
        btn_pgm.setTextSize(TypedValue.COMPLEX_UNIT_PX, 26);
        btn_pgm.setTextColor(this.getResources().getColor(R.color.white));
        btn_pgm.setBackgroundColor(this.getResources().getColor(R.color.btn_blue));
        layout_pgm.addView(btn_pgm);    

3、

INSTALL_FAILED_INVALID_APK: /data/app/vmdl654475879.tmp/8_slice__ signatures are inconsistent 

解决:
点击build下的clean project。重新run。

2、

今天在Android项目中按电源键锁屏,然后解锁,发现子Activity关闭了,回到了主页,这个问题困扰了我很久,最后打log发现,在按电源键的时候,调用了子Activity的onDestroy()方法,这个问题现在终于解决了在androidmanifest.xml中的各个activity的属性中加上android:configChanges="orientation|keyboardHidden"就可以解决这个问题。

另外防止屏幕锁屏可以在onCreate方法中调用

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

1、

android studio打开项目后一直Gradle:Resolve dependecies 'app_XXAPk'很长时间

buildscript {
    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        jcenter()
    }
}
注意:
1. 添加到Project级别的build.gradle中
2. 在buildscript与allprojects里都要添加
原文地址:https://www.cnblogs.com/lanqie/p/7442850.html