学习Android遇到的Bug

吐司出现项目名

小米高版本手机连上Android Stdio进行调试的时候,使用吐司会将项目名字也打印在上面,

Toast.makeText(MainActivity2.this,"Hello World!", Toast.LENGTH_SHORT).show();

打印为

MyApp:Hello World!

将上面代码修改为:

Toast toast = Toast.makeText(MainActivity2.this, "Hello World!", Toast.LENGTH_SHORT);
toast.setText("登录成功!");
toast.show();

手机无法修改按钮背景颜色

使用线性布局进行练习的时候,在Butten标签修改背景色时无论使用图片都无法修改背景色,按钮字体颜色和大小都能修改

修改配置文件,更改当前使用的主题,将蓝色框修改为红色,

修改完毕之后,出现了新问题,在运行程序的时候按钮颜色的确改过来了,可是预览时的颜色依然没有改变(还是紫色)

需要修改这个文件

这里添加.Bridge

运行Main方法系统报错

FAILURE: Build failed with an exception.

* Where:
Initialization script 'C:\Users\Administrator\AppData\Local\Temp\GetBean_main__.gradle' line: 21

* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:GetBean.main()'.
   > SourceSet with name 'main' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

意思就是没有找到Main方法的相关包,无法完成编译,

解决办法一

切换Project目录视图:.idea->gradle.xml->第七行->value改为false,重新编译运行

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="GradleMigrationSettings" migrationVersion="1" />
  <component name="GradleSettings">
    <option name="linkedExternalProjectsSettings">
      <GradleProjectSettings>
        <option name="delegatedBuild" value="false" />
        <option name="testRunner" value="PLATFORM" />
        <option name="distributionType" value="DEFAULT_WRAPPED" />
        <option name="externalProjectPath" value="$PROJECT_DIR$" />
        <option name="modules">
          <set>
            <option value="$PROJECT_DIR$" />
            <option value="$PROJECT_DIR$/app" />
          </set>
        </option>
        <option name="resolveModulePerSourceSet" value="false" />
        <option name="useQualifiedModuleNames" value="true" />
      </GradleProjectSettings>
    </option>
  </component>
</project>

解决办法二

项目根目录->gradle.properties,加入android.enableAapt2=false

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
android.enableAapt2=false
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值