首页 > 代码库 > android: button 属性

android: button 属性

代码中常用属性:

Button bt=new Buttion(Context context);

setClickable(boolean clickable)

设置按钮是否允许点击。

clickable=true:允许点击

clickable=false:禁止点击

setBackgroundResource(int resid)

通过资源文件设置背景色。

resid:资源xml文件ID。

按钮默认背景为:android.R.drawable.btn_default

setText(CharSequence text)设置按钮显示文字。
setTextColor(int color)

设置按钮显示文字的颜色。

color可以使用系统Color常量,例如 Color.BLACK等。

setOnClickListener(OnClickListener l)设置按钮点击事件
  

 

xml中常用属性:

android:layout_width=""---控件宽

android:layout_height=""---控件高

android:layout_weight=""---控件权重

android:text=""---控件上的文本内容

android:onClick="doClick"---点击此控件时调用的方法---方法名称为:doClick

android:drawableTop=""---在Button组件上放置图片