一、基础准备

Imagebutton 继承 Imageview,就是用一个图标代表了一些文字,它没Android:text属性。它由Android:src指定图标的位置
android:src="@drawable/back"

Button 继承 Textview,所以TextView的一些属性也适用于Button控件。

Button把图片当作背景与放在ImageButton/ImageView中的效果是不一样的。

二、代码

1、 如何设置按钮的样式?

<Button android:id="@+id/myBtn1" android:text="按钮1 设置背景样式" 
 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
 
     android:background="#fff000" /> 

2、如何设置背景图标

<Button android:id="@+id/myBtn6" android:text="按钮6 设置背景图标" 
 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
 
      android:textStyle="bold" android:background="@drawable/back_48" 
 
       /> 

3.如何设置按钮的文字颜色

<Button android:id="@+id/myBtn2" android:text="按钮2 字体颜色" 
 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
 
     android:textColor="#ff0000" /> 

4、 如何设置按钮的文字样式

<Button android:id="@+id/myBtn3" android:text="按钮3字体加粗" 
 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
 
     android:textColor="#ff0000" android:textStyle="bold" />

5、 如何为按钮添加监听器注册事件

myBtn4.setOnClickListener(new OnClickListener() { 
                     @Override 
 
                     public void onClick(View v) { 
 
                            myBtn4.setText("setOnclickListener事件监听注册成功"); 
                     } 
              }); 

1、 怎么样设置ImageButton的图标位置

Android : src

2、 怎么样为ImageButton添加监听器注册事件

实现Onclick

或者android:onClick="ImageButtonXml"

1、 设置透明度

imgBtn01.setAlpha(50);//设置透明度

更多相关文章

  1. Android(安卓)点击back键两次退出程序
  2. Android(安卓)中文 API (30) ―― CompoundButton.OnCheckedChange
  3. Android(安卓)ActionBar中的按钮添加旋转动画
  4. Android中设计具有背景图的按钮—ImageButton的焦点及事件处理
  5. 【Android】对话框 AlertDialog
  6. Android实现微信右上角弹出的菜单
  7. 【android】Eclipse集成android开发环境(IDE)搭建
  8. [Android] 一键修改从网上厨房制作的Android百分比电量过大的问
  9. Android导入源码

随机推荐

  1. 修改ZXing for Android为竖屏模式
  2. android的四大组件及其生命周期
  3. Android(安卓)布局中 如何使控件居中
  4. Android中RelativeLayout的字符水平(垂直
  5. Android开发前奏
  6. 【Android工场】Android(安卓)Input Syst
  7. android基础入门控件详解(3)
  8. 界面布局
  9. Android(安卓)Animation学习笔记
  10. Android(安卓)Studio加速