出现的一些小状况:

小状况

报错,代码显示运行成功

但是无法在模拟机上显示

原因是没有在包含应有id

其二是关于设置背景颜色中

关于background与backgroundTint的区别

//这是backgroundTint的源码
<!-- Tint to apply to the background. -->
<attr name="backgroundTint" format="color" /> //这是background的源码
<!-- A drawable to use as the background. This can be either a reference
to a full drawable resource (such as a PNG image, 9-patch,
XML state list description, etc), or a solid color such as "#ff000000"
(black). -->
<attr name="background" format="reference|color" />
  • 其实这个注释已经说了backgroundTint是应用到背景上的色彩
  • 而background是一个可绘制的背景,可以是一个完全可绘制资源的引用(例如图片、可调整大小位图9-patch、XML状态列表描述、etc),或者是纯色如黑色。

自然就是,如果你只是要给背景上纯色的话,建议用backgroundTint,如果你要用背景图片的话,就用background,可以分别提高对应的执行效率!!!

其三

关于Android drawable和drawable-v24文件夹有什么区别

当我们放入图片在drawable-v24文件夹时,在该文件夹引用该图片时会导致模拟器无法运行

经常我们放置图片一般默认drawable,mipmap-hdpi,mipmap-mdpi,mipmap-xhdpi文件夹下,这样的情况下我们运行起来的APP也不会出现什么问题。那么如果图片放在drawable-v24,mipmap-anydpi-v26文件夹下就会出现问题。

两个文件夹的区别是:用于为设备兼容性和不同的Android版本提供不同的屏幕密度

所以解决办法就是把图片放在drawable文件夹中这样模拟器就会正常运行了。

使用Button标签的相关效果展示及其代码

button标签可以实现界面跳转、描边、圆角、提示信息(toast)

实现效果

部分代码

(点击信息代码.java文件)

package com.example.app02;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast; public class ButtonActivity extends AppCompatActivity { private Button mBtn3;
private TextView tv1;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button); mBtn3=findViewById(R.id.btn_3);
mBtn3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(ButtonActivity.this, "btn3被点击了!", Toast.LENGTH_SHORT).show();
}
}); tv1=findViewById(R.id.tv_1);
tv1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(ButtonActivity.this, "tv1被点击了", Toast.LENGTH_SHORT).show();;
}
});
}
public void showToast(View view){
Toast.makeText(this, "btn4被点击了!", Toast.LENGTH_SHORT).show();
}
}

(相关标签.xml文件)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<Button
android:id="@+id/btn_1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="按钮1"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:backgroundTint="#FF0000"/>
<Button
android:id="@+id/btn_2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="按钮2"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:background="@drawable/bg_btn2"
android:layout_marginTop="10dp"
android:layout_below="@+id/btn_1"/>
<Button
android:id="@+id/btn_3"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/btn_2"
android:text="按钮3"
android:textSize="20sp"
android:textColor="#FF9900"
android:layout_marginTop="10dp"
android:background="@drawable/bg_btn3"/>
<Button
android:id="@+id/btn_4"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="按钮4"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:layout_below="@id/btn_3"
android:onClick="showToast"
android:background="@drawable/bg_btn4"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/tv_1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textColor="#000000"
android:text="文字1"
android:textSize="20sp"
android:layout_below="@id/btn_4"
android:gravity="center"
android:background="#FF9900"
android:layout_marginTop="10dp"/> </Rel

(跳转界面.java文件)

package com.example.app02;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; public class MainActivity extends AppCompatActivity {
//先声明空间
private Button mBtnTextView;
private Button mBtnButton;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBtnTextView = findViewById(R.id.btn_textview);
mBtnTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 跳转到TextView演示界面
Intent intent = new Intent(MainActivity.this, TextViewActivity.class);
startActivity(intent);
}
});
mBtnButton= findViewById(R.id.btn_button);
mBtnButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 跳转到Button演示界面
Intent intent=new Intent(MainActivity.this,ButtonActivity.class);
startActivity(intent);
}
});
}
}

Android学习day04【Button】的更多相关文章

  1. Android学习起步 - Button按钮及事件处理

    按钮和文本框算是比较简单的控件了,以下主要讲按钮的事件响应,三种写法(匿名内部类响应事件.外部类响应事件.本类直接响应事件) 点击按钮后文本框中会显示 ”按钮被单击了”,先看效果: 以下是这个界面的布 ...

  2. Android学习笔记-Button(按钮)

    Button是TextView的子类,所以TextView上很多属性也可以应用到Button 上!我们实际开发中对于Button的,无非是对按钮的几个状态做相应的操作,比如:按钮按下的时候 用一种颜色 ...

  3. 我的android学习脚步----------- Button 和监听器setonclicklistener

    最基本的学习,设置一个按钮并监听实现实时时刻显示 首先XML布局,在layout中的  activity_main.xml中拖一个Button按钮到相应位置 然后在xml文件中做修改 <Rela ...

  4. Android学习笔记——Button

    该工程的功能是实现在activity中显示一个TextView和一个Button 以下代码是MainActivity中的代码 package com.example.button; import an ...

  5. Android学习之Button按钮在程序运行时全部变大写的处理

    问题: 在layout布局文件中,我们命名的按钮名称是“button1”,程序运行过后,在app上显示出来的是“BUTTON1”,先看源代码和效果: 按钮源代码: 运行效果: 解决办法: 方法一: 在 ...

  6. android学习日记03--常用控件button/imagebutton

    常用控件 控件是对数据和方法的封装.控件可以有自己的属性和方法.属性是控件数据的简单访问者.方法则是控件的一些简单而可见的功能.所有控件都是继承View类 介绍android原生提供几种常用的控件bu ...

  7. Android学习之——实现圆角Button

    在drawable文件夹下新建btn_shape.xml文件: <?xml version="1.0" encoding="utf-8"?> < ...

  8. 【转】Pro Android学习笔记(十五):用户界面和控制(3):Button控件

    目录(?)[-] 基础Button ImageButton ToggleButton CheckBox RadioButton 基础Button Button是最常用的基础控件之一,在Android中 ...

  9. Android学习——Button填充颜色及实现圆角

    在drawable下新建文件夹bt_shape.xml,如下: <?xml version="1.0" encoding="utf-8"?> < ...

  10. Android学习路线总结,绝对干货

    title: Android学习路线总结,绝对干货 tags: Android学习路线,Android学习资料,怎么学习android grammar_cjkRuby: true --- 一.前言 不 ...

随机推荐

  1. 犯得一些zz错误

    本文用于警戒自己,不要再犯以前的傻逼错误 noip没建子文件夹导致爆零 知道关同步流之后还用endl,导致超时 使用'\n'代替endl 3.多组测试数据使用for循环占用了 i 变量名,后面在for ...

  2. SpringBoot对接OpenAI

    SpringBoot对接OpenAI 随着人工智能技术的飞速发展,越来越多的开发者希望将智能功能集成到自己的应用中,以提升用户体验和应用的功能.OpenAI作为一家领先的人工智能公司,提供了许多先进的 ...

  3. MySQL配置简单优化与读写测试

    测试方法 先使用sysbench对默认配置的MySQL单节点进行压测,单表数据量为100万,数据库总数据量为2000万,每次压测300秒. sysbench --db-driver=mysql --t ...

  4. Nginx反向代理服务流式输出设置

    Nginx反向代理服务流式输出设置 1.问题场景 提问:为什么我部署的服务没有流式响应 最近在重构原有的GPT项目时,遇到gpt回答速度很慢的现象.在使用流式输出的接口时,接口响应速度居然还是达到了3 ...

  5. Callback Function Essence

    Include Example Input: I am a. route execute finish. I am b. route execute finish. What is Callback ...

  6. 解决git出现fatal: detected dubious ownership in repository at XXXXX的错误

    在window环境下,使用git命令时报错fatal: detected dubious ownership in repository at XXXXXX,图片如下 解决方法如下 添加一行代码 gi ...

  7. 产品代码都给你看了,可别再说不会DDD(五):请求处理流程

    这是一个讲解DDD落地的文章系列,作者是<实现领域驱动设计>的译者滕云.本文章系列以一个真实的并已成功上线的软件项目--码如云(https://www.mryqr.com)为例,系统性地讲 ...

  8. 微信小程序隐私保护协议修改方法 uniapp

    微信隐私保护协议指南 一天天没事闲的   01 在manifest.json 中添加一行 "__usePrivacyCheck__" : false   02 自定义一个弹窗组件 ...

  9. Python基于Flask的高校舆情分析,舆情监控可视化系统

    一.前言在当今社会,舆情监控越来越被重视.随着互联网技术的发展,我们从传统媒体渠道.官方报告.调查问卷等方式搜集到的舆情信息,逐渐被网络上的内容所替代.因为网络上的内容传播速度快.及时性强.覆盖范围广 ...

  10. vue中watch侦听器,deep和immediate的用法

    1.deep深度监听的用法 当监听一个对象时,可能想监听整个对象的变化,而不仅仅是某个属性.但在默认情况下,如果你正在监听formData对象并且修改了formData.username,对应的侦听器 ...