Android常见控件— — —Button
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
> <TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="第一个textview"
android:textSize="24sp"
android:textColor="#ff0000"
android:gravity="center"
/> <Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text_view"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true"
android:text="确定"/> </RelativeLayout>
/**
*使用匿名类来注册监听器
*/
package com.example.uiwidgettest; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView; public class TextviewActivity extends Activity { private Button btn1;
private TextView tv; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.textview); btn1 = (Button)findViewById(R.id.btn1);
tv = (TextView)findViewById(R.id.text_view);
btn1.setOnClickListener(new View.OnClickListener(){ @Override
public void onClick(View v){
switch(v.getId()){
case R.id.tv:
tv.setText("TextView修改成功");
break;
default:
break;
}
}
});
}
}
/**
*实现接口的方式来注册监听器
*/
package com.example.uiwidgettest; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView; public class TextviewActivity extends Activity implements View.OnClickListener { private Button btn1;
private TextView tv; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.textview); btn1 = (Button)findViewById(R.id.btn1);
tv = (TextView)findViewById(R.id.text_view); btn1.setOnClickListener(this);
} @Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn1:
tv.setText("ok");
break;
default:
break;
}
}
}
Android常见控件— — —Button的更多相关文章
- Android基础控件Button的使用
1.相关属性 Android的按钮有Button和ImageButton(图像按钮),Button extends TextView, ImageButton extends ImageView! a ...
- Android -- 常见控件的小效果
1,EditText控件 ① 修改光标颜色 自定义drawable 创建cursor.xml文件 <?xml version="1.0" encoding="utf ...
- Android --> 常见控件
1.TextView 主要用于界面上显示一段文本信息 2.Button 用于和用户交互的一个按钮控件 //为Button点击事件注册一个监听器public class Click extends ...
- Android常见控件— — —ProgressBar
ProgressBar用于在界面上显示一个进度条,表示我们的程序正在加载一些数据. <?xml version="1.0" encoding="utf-8" ...
- Android常见控件— — —ProgressDialog
package com.example.uiwidgettest2; import android.app.Activity;import android.app.AlertDialog;import ...
- Android常见控件— — —AlertDialog
package com.example.uiwidgettest2; import android.app.Activity;import android.app.AlertDialog;import ...
- Android常见控件— — —EditText
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...
- Android常见控件— — —TextView
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=&qu ...
- Android 中常见控件的介绍和使用
1 TextView文本框 1.1 TextView类的结构 TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显示文本的区域.TextView类的层次关系如下: java.la ...
随机推荐
- 卸载cygwin
1.下载takeown.exe(貌似win自带,你可以打开cmd 输入takeown.exe查看,貌似不行)所以还是去网上下载吧,亲测http://download.csdn.net/download ...
- zigbee学习之路(八):定时器1(中断)
一.前言 通过上次的实验,我们已经学会了定时器3的中断方式,这次,我们来看看定时器1通过中断怎么控制. 二.原理分析 定时器1的初始化跟前面提到的一样,也是要配置寄存器T1CTL,还要进行开中断的操作 ...
- Redundant Paths-POJ3177(并查集+双连通分量)
Redundant Paths Description In order to get from one of the F (1 <= F <= 5,000) grazing fields ...
- elasticsearch安装与基础用法
来自官网,版本为2.3 注意elasticsearch依赖jdk,2.3依赖jdk7 下载rpm包并安装 wget -c https://download.elastic.co/elasticsear ...
- GMF:如何让网格显示在background,而不是foreground
前言 很久没写文章了,准备写一系列关于Eclipse RCP /Plugin的文章. 这些文章都是trouble shooting性质的,不准备写的很细,当你碰到这样的问题,google到时,能帮你把 ...
- <转>linux crontab 定时任务
基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 ...
- 10-JS数组
数组的定义和创建 数组是值得有序集合.JavaScript数组是无类型的. 数组对象的作用是:使用单独的变量名来存储一系列的值. 数组的创建 有两种向数组赋值的方法(你可以添加任意多的值,就像你可以定 ...
- 开发板A/D转换原理
A/D转换器(Analog-to-Digital Converter)又叫模/数转换器,即使将模拟信(电压或是电流的形式)转换成数字信号.这种数字信号可让仪表,计算机外设接口或是微处理机来加以操作或是 ...
- 利用backtrace和objdump进行分析挂掉的程序
转自:http://blog.csdn.net/hanchaoman/article/details/5583457 汇编不懂,先把方法记下来. glibc为我们提供了此类能够dump栈内容的函数簇, ...
- jquery mobile 和phonegap开发总结之三跨域加载页面
跨域加载 一要进行一定的配置见下面 $( document ).bind( "mobileinit", function() { // Make your jQuery Mobil ...