Android项目报错收录

导入项目报错

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();

实现效果:
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值