掌握Android常用控件之Button与ImageButton的用法,熟悉它们的常用属性。

1.相关代码:
activity_main.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="#ffffff"tools:context=".MainActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:paddingTop="10dp"android:paddingBottom="10dp"android:paddingLeft="20dp"android:paddingRight="30dp"android:orientation="horizontal"><EditTextandroid:id="@+id/edit1"android:layout_width="wrap_content"android:layout_height="50dp"android:layout_weight="6"android:hint="搜索" /><Buttonandroid:id="@+id/bt1"android:layout_width="wrap_content"android:layout_height="70dp"android:layout_weight="1"android:text="→"android:textSize="50dp"android:layout_gravity="center"android:background="@color/c1"android:textColor="#000000"/></LinearLayout><ImageButtonandroid:id="@+id/imgBt1"android:layout_width="400dp"android:layout_height="200dp"android:scaleType="fitCenter"android:background="#ffffff"app:srcCompat="@drawable/img1" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:paddingTop="10dp"android:paddingBottom="10dp"android:paddingLeft="20dp"android:paddingRight="30dp"android:orientation="horizontal"><Buttonandroid:id="@+id/bt2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:background="#7bb6ff"android:text="排行"/><Buttonandroid:id="@+id/bt3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:background="#94E91E7D"android:text="炫动字体" /><Buttonandroid:id="@+id/bt4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:background="#FF5722"android:text="Mate40" /><Buttonandroid:id="@+id/bt5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:background="#CDDC39"android:text="新字" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:paddingTop="5dp"android:paddingBottom="10dp"android:paddingLeft="5dp"android:paddingRight="5dp"><ImageButtonandroid:id="@+id/imgBt2"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:background="#ffffff"app:srcCompat="@drawable/bt_del" /><ImageButtonandroid:id="@+id/imgBt3"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:background="#ffffff"app:srcCompat="@drawable/bt_del1" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:paddingLeft="5dp"android:paddingRight="5dp"><ImageButtonandroid:id="@+id/imgBt4"android:layout_width="match_parent"android:layout_height="wrap_content"android:paddingRight="10dp"android:layout_weight="1"android:background="#ffffff"app:srcCompat="@drawable/bt_del3" /><ImageButtonandroid:id="@+id/imgBt5"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:background="#ffffff"app:srcCompat="@drawable/bt_del2" /></LinearLayout></LinearLayout>

MainActivity.java代码:

package com.example.sy6;import androidx.appcompat.app.AppCompatActivity;import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;public class MainActivity extends AppCompatActivity {EditText edit1;Button bt1;Button bt2;Button bt3;Button bt4;Button bt5;ImageButton imgBt1;ImageButton imgBt2;ImageButton imgBt3;ImageButton imgBt4;ImageButton imgBt5;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);edit1 = findViewById(R.id.edit1);bt1 = findViewById(R.id.bt1);bt2 = findViewById(R.id.bt2);bt3 = findViewById(R.id.bt3);bt4 = findViewById(R.id.bt4);bt5 = findViewById(R.id.bt5);imgBt1 = findViewById(R.id.imgBt1);imgBt2 = findViewById(R.id.imgBt2);imgBt3 = findViewById(R.id.imgBt3);imgBt4 = findViewById(R.id.imgBt4);imgBt5 = findViewById(R.id.imgBt5);bt1.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Uri uri1 = Uri.parse("https://url.cloud.huawei.com/6xyIAzGyxq");Intent intent1 = new Intent(Intent.ACTION_VIEW, uri1);startActivity(intent1);}});bt2.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(MainActivity.this, "华为手机主题排行榜",Toast.LENGTH_LONG).show();bt2.setBackgroundResource(R.drawable.bt_c);bt2.setText("ranking list");bt2.setTextColor(Color.rgb(255,150,46));}});bt3.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(MainActivity.this, "华为炫动字体",Toast.LENGTH_LONG).show();}});bt4.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(MainActivity.this, "华为最新款Mate40手机",Toast.LENGTH_LONG).show();bt4.setBackgroundResource(R.drawable.bt_c);bt4.setText("Mate40 Phone");bt4.setTextColor(Color.rgb(255,150,46));}});bt5.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(MainActivity.this, "华为新字体",Toast.LENGTH_LONG).show();bt5.setBackgroundResource(R.drawable.bt_c);bt5.setText("new words");bt5.setTextColor(Color.rgb(255,150,46));}});imgBt1.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Uri uri2 = Uri.parse("https://url.cloud.huawei.com/6iVlsp5pRu");Intent intent2 = new Intent(Intent.ACTION_VIEW, uri2);startActivity(intent2);}});imgBt2.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(MainActivity.this, "随你去天涯追月亮 ¥6.00",Toast.LENGTH_LONG).show();}});imgBt3.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(MainActivity.this, "生活明朗万物可爱 ¥7.00",Toast.LENGTH_LONG).show();}});imgBt4.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(MainActivity.this, "许你一世繁华 ¥12.00",Toast.LENGTH_LONG).show();}});imgBt5.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(MainActivity.this, "方正拼音体 ¥5.00",Toast.LENGTH_LONG).show();}});}
}

2.效果图:




Android常用控件之Button与ImageButton相关推荐

  1. Android学习--02(猜猜我的星座App源码+Android常用控件TextView+EditText+Button+ImangeView+DatePicker+App间通信+跳转页面)

    猜猜我的星座App 1 Android常用控件 1.1 TextView控件 1.1.1 简介 1.1.2属性 1.1.3 扩展属性 1.1.4 TextView的使用方法 1.1.5总结 1.2 E ...

  2. Android常用控件有哪些?如何使用?

    Android常用控件介绍及使用 控件 TextView 显示文字,相当于Panel ImageView 显示图片 EditText 输入框,可编辑,可设置软键盘方式 Button 按钮,可附带图片 ...

  3. Android常用控件,四大组件,intent应用

    常用控件:TextView. Button. EditText. ImageView. ProgressBar.AlterDailog. ProgressDailog 四大组件: Activity(活 ...

  4. android常用控件实验报告,常用控件的编程实验报告

    实验二 常用控件的编程 一.实验目的和要求 (1)掌握窗口下拉列表框.选择钮.组合框.多行编辑框等常用控件的基本使用方法和编程方法: (2)掌握窗口控件的齐整性操纵方法以及Tab顺序的设置: (3)掌 ...

  5. android的控件常用方法是,Android常用控件属性分析

    1.TextView 单行文本输入框,使用过的事件是onClickListener android:gravity="right':设置内容的对其方式 android:layout_grav ...

  6. android基础 [超级详细android常用控件解析(ScollView控件,ProgressBar进度条,PopupWindow控件)]

    目录 1 章节目录 2 ScollView控件 2.1 ScrollView简介 2.2 ScrollView使用 2.3 常用属性及方法 3 ProgressBar进度条 3.1 简介 3.2 常用 ...

  7. Android基础控件之Button的基本使用

    Button基础 用户界面部分学起来还真是无处下手哇,总不能一个控件发一篇文吧,略有点费时间啊...这个难道不是边用边学才给力吗..所以我打算从最实用的Button开始下手. 先贴几个链接,好东西: ...

  8. android常用控件实验报告,ui设计实验报告.doc

    ui设计实验报告 ui设计实验报告 篇一:UI设计实验报告 实验项目四:UI设计 一. 实验目的和要求 1.熟练运用Eclipse软件中的swing设计. 2.掌握UI编写的软件. 3.能都熟练的进行 ...

  9. Android常用控件之Fragment仿Android4.0设置界面

    Fragment是Android3.0新增的概念,是碎片的意思,它和Activity很相像,用来在一个Activity中描述一些行为或部分用户界面:使用多个Fragment可以在一个单独的Activi ...

最新文章

  1. 十四、Java练习:一个猜数游戏
  2. 将隐式神经表示(INR)用于2D图像
  3. ASP.NET Core快速入门(第4章:ASP.NET Core HTTP介绍)--学习笔记
  4. wincc与第三方软件opc通讯_OPC 通讯不得不说的强大软件
  5. Tomcat假死的原因及解决方案
  6. [bzoj 1452] [JSOI2009]Count
  7. 渲染标签文字(光晕效果)
  8. 栈--后进先出的线性表
  9. 如何用matlab求出矩阵简化阶梯形顺带算出主元所在的列
  10. Android手机屏幕的三种状态
  11. Lync/Skype脱机地址簿不更新
  12. QT技巧系列(5)按时间顺序列出目录下所有的文件名
  13. 红米K30S至尊纪念版和小米10至尊纪念版的区别
  14. matlab海龟交易策略,【策略篇】海龟交易系统使用方法和源码
  15. 安装maven时安照说明配置环境变量JAVA_HOME
  16. DD驱动鼠标键盘(驱动级别机器人使用鼠标键盘)
  17. 神奇哈哈镜-第14届蓝桥杯省赛Scratch初级组真题第3题
  18. html5 翻页第三方,谣言终止,NS使用第三方底座变砖真相揭晓
  19. public static Object service(String url, World至浏览
  20. react native 安卓实现自动下载更新版本

热门文章

  1. sangerbox制作heapmap_使用highmaps制作中国地图
  2. 安卓强制恢复出厂_手机恢复出厂设置后,与新手机的区别已被确认,望大家相互转告!...
  3. 笔录软件在linux系统,linux下f但tp服务器架设笔录.doc
  4. 七、golang中接口、反射
  5. 华硕设置u盘启动linux,华硕主板怎么设置u盘启动_利用它的快捷键就可以了 - 驱动管家...
  6. 电子工程师必须懂得如何规划自己的人生
  7. 【蓝桥杯试题 练习题 不定方程求解】
  8. 污点修复代码_立即修复该代码!
  9. cvte 前端一面 凉经
  10. java基于聚类的离群点检测_基于两步聚类的离群点检测