热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

20221011学习内容

1.Button1.1activity_button_view.xml

1.Button

1.1activity_button_view.xml

xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width
="match_parent"
android:layout_height
="match_parent"
android:orientation
="vertical"
android:padding
="5dp">
<TextView
android:layout_width="match_parent"
android:layout_height
="wrap_content"
android:gravity
="center"
android:text
="下面的按钮英文默认大写"
android:textColor
="@color/black"
android:textSize
="17sp" />
<Button
android:layout_width="match_parent"
android:layout_height
="wrap_content"
android:text
="Hello World"
android:textColor
="@color/black"
android:textSize
="17sp" />
<TextView
android:layout_width="match_parent"
android:layout_height
="wrap_content"
android:gravity
="center"
android:text
="下面的按钮英文保持原状"
android:textColor
="@color/black"
android:textSize
="17sp" />
<Button
android:layout_width="match_parent"
android:layout_height
="wrap_content"
android:text
="Hello World"
android:textAllCaps
="false"
android:textColor
="@color/black"
android:textSize
="17sp" />
<Button
android:layout_width="match_parent"
android:layout_height
="wrap_content"
android:text
="直接指定点击方法"
android:textAllCaps
="false"
android:textColor
="@color/black"
android:textSize
="17sp"
android:onClick
="doClick"/>
<TextView
android:id="@+id/tv_result"
android:layout_width
="match_parent"
android:layout_height
="wrap_content"
android:text
="这里查看按钮的点击结果"
android:textColor
="@color/black"
android:textSize
="17sp" />
LinearLayout>

1.2ButtonStyleActivity.java

package com.example.chapter03;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.example.chapter03.utils.DateUtil;
public class ButtonStyleActivity extends AppCompatActivity {
// 快捷键 ctrl+alt+f 把onCreate方法中的局部变量提取成全局的属性
private TextView tv_result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button_style);
tv_result
= findViewById(R.id.tv_result);
}
public void doClick(View view) {
String desc
= String.format("%s 您点击了按钮; %s", DateUtil.getNowTime(), ((Button)view).getText());
tv_result.setText(desc);
}
}

1.3DateUtil.java

package com.example.chapter03.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtil {
public static String getNowTime() {
SimpleDateFormat sdf
= new SimpleDateFormat("HH:mm:ss");
return sdf.format(new Date());
}
}

1.4效果

2.点击事件

2.1activity_button_click.xml

xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width
="match_parent"
android:layout_height
="match_parent"
android:orientation
="vertical">
<Button
android:id="@+id/btn_click_single"
android:layout_width
="match_parent"
android:layout_height
="wrap_content"
android:text
="指定单独的点击监听器"
android:textColor
="#000000"
android:textSize
="15sp" />
<TextView
android:id="@+id/tv_result"
android:layout_width
="match_parent"
android:layout_height
="wrap_content"
android:padding
="5dp"
android:gravity
="center"
android:textColor
="#000000"
android:textSize
="15sp"
android:text
="这里查看按钮的点击结果"/>
LinearLayout>

2.2ButtonClickActivity.java

package com.example.chapter03;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.example.chapter03.utils.DateUtil;
public class ButtonClickActivity extends AppCompatActivity {
// ctrl+alt+f
private TextView tv_result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button_click);
tv_result
= findViewById(R.id.tv_result);
Button btn_click_single
= findViewById(R.id.btn_click_single);
btn_click_single.setOnClickListener(
new MyViewOnClickListener(tv_result));
}
static class MyViewOnClickListener implements View.OnClickListener {
private final TextView tv_result;
public MyViewOnClickListener(TextView tv_result) {
this.tv_result = tv_result;
}
@Override
public void onClick(View v) {
String desc
= String.format("%s 您点击了按钮; %s", DateUtil.getNowTime(), ((Button)v).getText());
tv_result.setText(desc);
}
}
}

2.3效果

 

2.4activity_button_click.xml

xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width
="match_parent"
android:layout_height
="match_parent"
android:orientation
="vertical">
<Button
android:id="@+id/btn_click_single"
android:layout_width
="match_parent"
android:layout_height
="wrap_content"
android:text
="指定单独的点击监听器"
android:textColor
="#000000"
android:textSize
="15sp" />
<Button
android:id="@+id/btn_click_public"
android:layout_width
="match_parent"
android:layout_height
="wrap_content"
android:text
="指定公共的点击监听器"
android:textColor
="#000000"
android:textSize
="15sp" />
<TextView
android:id="@+id/tv_result"
android:layout_width
="match_parent"
android:layout_height
="wrap_content"
android:padding
="5dp"
android:gravity
="center"
android:textColor
="#000000"
android:textSize
="15sp"
android:text
="这里查看按钮的点击结果"/>
LinearLayout>

2.5ButtonClickActivity.java

package com.example.chapter03;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.example.chapter03.utils.DateUtil;
public class ButtonClickActivity extends AppCompatActivity implements View.OnClickListener {
// ctrl+alt+f
private TextView tv_result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button_click);
tv_result
= findViewById(R.id.tv_result);
Button btn_click_single
= findViewById(R.id.btn_click_single);
btn_click_single.setOnClickListener(
new MyViewOnClickListener(tv_result));
Button btn_click_public
= findViewById(R.id.btn_click_public);
btn_click_public.setOnClickListener(
this);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.btn_click_public) {
String desc
= String.format("%s 您点击了按钮; %s", DateUtil.getNowTime(), ((Button)v).getText());
tv_result.setText(desc);
}
}
static class MyViewOnClickListener implements View.OnClickListener {
private final TextView tv_result;
public MyViewOnClickListener(TextView tv_result) {
this.tv_result = tv_result;
}
@Override
public void onClick(View v) {
String desc
= String.format("%s 您点击了按钮; %s", DateUtil.getNowTime(), ((Button)v).getText());
tv_result.setText(desc);
}
}
}

2.6效果

 



推荐阅读
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • 本文介绍了使用kotlin实现动画效果的方法,包括上下移动、放大缩小、旋转等功能。通过代码示例演示了如何使用ObjectAnimator和AnimatorSet来实现动画效果,并提供了实现抖动效果的代码。同时还介绍了如何使用translationY和translationX来实现上下和左右移动的效果。最后还提供了一个anim_small.xml文件的代码示例,可以用来实现放大缩小的效果。 ... [详细]
  • 本文讲述了如何通过代码在Android中更改Recycler视图项的背景颜色。通过在onBindViewHolder方法中设置条件判断,可以实现根据条件改变背景颜色的效果。同时,还介绍了如何修改底部边框颜色以及提供了RecyclerView Fragment layout.xml和项目布局文件的示例代码。 ... [详细]
  • 拥抱Android Design Support Library新变化(导航视图、悬浮ActionBar)
    转载请注明明桑AndroidAndroid5.0Loollipop作为Android最重要的版本之一,为我们带来了全新的界面风格和设计语言。看起来很受欢迎࿰ ... [详细]
  • C# WPF自定义按钮的方法
    本文介绍了在C# WPF中实现自定义按钮的方法,包括使用图片作为按钮背景、自定义鼠标进入效果、自定义按压效果和自定义禁用效果。通过创建CustomButton.cs类和ButtonStyles.xaml资源文件,设计按钮的Style并添加所需的依赖属性,可以实现自定义按钮的效果。示例代码在ButtonStyles.xaml中给出。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文讨论了在Spring 3.1中,数据源未能自动连接到@Configuration类的错误原因,并提供了解决方法。作者发现了错误的原因,并在代码中手动定义了PersistenceAnnotationBeanPostProcessor。作者删除了该定义后,问题得到解决。此外,作者还指出了默认的PersistenceAnnotationBeanPostProcessor的注册方式,并提供了自定义该bean定义的方法。 ... [详细]
  • eclipse学习(第三章:ssh中的Hibernate)——11.Hibernate的缓存(2级缓存,get和load)
    本文介绍了eclipse学习中的第三章内容,主要讲解了ssh中的Hibernate的缓存,包括2级缓存和get方法、load方法的区别。文章还涉及了项目实践和相关知识点的讲解。 ... [详细]
  • 本文详细介绍了Java中vector的使用方法和相关知识,包括vector类的功能、构造方法和使用注意事项。通过使用vector类,可以方便地实现动态数组的功能,并且可以随意插入不同类型的对象,进行查找、插入和删除操作。这篇文章对于需要频繁进行查找、插入和删除操作的情况下,使用vector类是一个很好的选择。 ... [详细]
  • 本文介绍了在Vue项目中如何结合Element UI解决连续上传多张图片及图片编辑的问题。作者强调了在编码前要明确需求和所需要的结果,并详细描述了自己的代码实现过程。 ... [详细]
  • 猜字母游戏
    猜字母游戏猜字母游戏——设计数据结构猜字母游戏——设计程序结构猜字母游戏——实现字母生成方法猜字母游戏——实现字母检测方法猜字母游戏——实现主方法1猜字母游戏——设计数据结构1.1 ... [详细]
author-avatar
路霄峰_121
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有