Android widget之Button
来源:互联网 发布:java内部类的调用 编辑:程序博客网 时间:2024/06/06 03:53
简介
表示按钮小部件,用户可以按下按钮来执行操作。
- 直接父类TextView
- 直接子类
- AppCompatButton
- CompoundButton
- 间接子类
- AppCompatCheckBox
- AppCompatRadioButton
- CheckBox
- RadioButton
- Switch
- SwitchCompat
- ToggleButton
使用
在使用上与TextView没有差别,只是谷歌官方为Button按钮内置了,点击的动画与按钮背景。
用途
public class MainActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.button_id); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // 点击按钮之后的操作 } }); } }
也可以在xml布局文件中配置
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="我是一个Button按钮" android:onClick="selfDestruct" />
如果这样配置,就必须在对应的activity中
public void selfDestruct(View view) { // 点击按钮之后的操作 }
- 注:该方法必须为公开的
当然有点击事件的监听,必然就有长按与手势的监听,既然继承的TextView必然也会有文本改变的监听。
- OnLongClickListener —> 长按
- OnTouchListener —> 手势
- TextWatcher —> 文本改变
属性
Button的属性基本来自TextView
可以说Button按钮就是TextView加了一个背景和一个点击动画,其他的所有属性方法都来TextView。
知识贵在分享!
阅读全文
1 0
- Android widget之Button
- android widget组件之Button
- android--widget介绍之Button
- android.widget.textview cannot be casted to android.widget.button
- android.widget.Button cannot be cast to android.widget.Gallery
- widget.Button cannot be cast to android.widget.ListView
- java.lang.NoSuchMethodError: android.widget.Button.setBackground
- java.lang.ClassCastException: android.widget.Button异常
- android:Widget.Material.Button.Colored找不到
- Android widget 之RemoteView
- Android widget 之RemoteView
- android widget之TextView
- android widget 之EditText
- android widget 之CheckBox
- Android之Widget
- Android widget 之RemoteView
- android--widget之menu
- Android widget 之RemoteView
- ${pageContext.request.contextPath} JSP取得绝对路径
- spring使用注意事项
- JAVA正则表达式
- EnvironmentCapable
- Java中日期或时间大小的比对
- Android widget之Button
- 数据结构循环链表基本操作实例演示
- SpringMVC 详解
- android studio 模拟器 开机提示 需要输入密码 To start Android,enter your password
- 八大排序算法之选择排序
- response.setHeader的各种用法
- javascript 里面for in while do while swich for 的区别
- java MethodHandle解析
- Easyui 控件的启用与禁用