导入项目报错
your project file contains non-ASCII characters
检查路径中是否有中文,并更改之
导入项目后,build报错
没有引入buildscript;
build.gradle 下载超级慢解决
buildgradle使用的是谷歌服务器,一些国外的依赖下载极慢,所以引入阿里镜像。
buildscript {
repositories {
// google()
// jcenter()
repositories {
//google()
//jcenter()
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/google/'}
maven { url 'https://maven.aliyun.com/repository/jcenter/'}
mavenLocal()
mavenCentral()
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
allprojects {
repositories {
//google()
//jcenter()
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/google/'}
maven { url 'https://maven.aliyun.com/repository/jcenter/'}
mavenLocal()
mavenCentral()
}
}
速度有了质的飞跃。
Toast利用setGravity(int,int,int )设置Toast的位置无效
这里踩的坑:
setGravity() shouldn't be called on text toasts, the values won't be used
翻译过来的意思是:
不应在文本吐司上调用 setGravity(),不会使用这些值
这里无论如何设置setGravity(),toast始终位于底部的位置。
查看源码:
/**
* Text toasts will be rendered by SystemUI instead of in-app, so apps can't circumvent
* background custom toast restrictions.
*/
@ChangeId
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q)
private static final long CHANGE_TEXT_TOASTS_IN_THE_SYSTEM = 147798919L;
private final Binder mToken;
private final Context mContext;
private final Handler mHandler;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
根据这段代码字面意思来看可能是Q版本后的可用不过发生了一些变化,maxTagergetSdk最高到P版本就不可用了,P是28,Q是29
解决:
- 应该是targetSDKVersion的版本过高,需要降低版本,暂未尝试
- 或者不使用文本土司的,使用setView()的方式来替代setText()或者Toast.makeText()
如:
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.view_toast_custom,
(ViewGroup) findViewById(R.id.lly_toast));
ImageView img_logo = (ImageView) view.findViewById(R.id.img_logo);
TextView tv_msg = (TextView) view.findViewById(R.id.tv_msg);
tv_msg.setText(str);
Toast toast = new Toast(this);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(view);
toast.show();
实现效果: