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 ...
随机推荐
- Unity3D The Blacksmith Demo部分内容学习
1.Plane Reflection 平面反射 在角色包的例子里可以看到,该脚本使用一个特定的相机渲染反射内容 官方介绍说这是优于反射探头的一种做法 2.HairRenderer 毛发渲染器 单独写的 ...
- C++高精度计算代码运行时间(转载)
转载:http://blog.csdn.net/rrrfff/article/details/6583410 //在定时前应该先调用QueryPerformanceFrequency()函数获得机器内 ...
- PHP 回调、匿名函数和闭包
<?php class Product{ public $name; public $price; function __construct($name, $price){ $this-> ...
- SQL 向上取整、向下取整、四舍五入取整的实例!round、rounddown、roundup
sql server ==================================================== [四舍五入取整截取] select round(54.56,0) === ...
- Cheatsheet: 2015 11.01 ~ 11.30
Golang Roadomatic: Node vs. Go Quick Guide to Golang for Java Developers 3 Go Gotchas Web Choosing a ...
- [HIHO1107]Shortest Proper Prefix(trie)
题目链接:http://hihocoder.com/problemset/problem/1107 题意:求有多少非依赖前缀,使得前缀下标识的字符串不超过5个. 这里非依赖的意思是,假如前缀a,b,a ...
- Open source packages on self-driving car
Autoware https://github.com/CPFL/Autoware.git Open-source software for urban autonomous driving &quo ...
- HDU-4527 小明系列故事——玩转十滴水 模拟
题意:就是平时玩的十滴水游戏,游戏者拥有一定的水滴,能够滴在某些位置,如果一个点上的体积超过了4就会爆炸,向四周传递一个小水滴.该题就是要求模拟这个过程. 分析:这里有一个问题就是不能够使用递归来处理 ...
- [Prodinner项目]学习分享_第三部分_Service层(业务逻辑层)
前两节讲到怎样生成一个Model和怎样将Model映射到数据库,这一节将讲到业务逻辑层,也就是Service层. 1.Prodinner架构已经构建好的,基本的增删改查. 假设,我现在想操作第二节中讲 ...
- KDE、GNOME 和 XFCE 桌面比较
KDE.GNOME 和 XFCE 桌面比较 这么多年来,很多人一直都在他们的 linux 桌面端使用 KDE 或者 GNOME 桌面环境.在这两个桌面环境多年不断发展的同时,其它的桌面也在持续增加 ...