ImageButton和Button区别

一、基础准备

      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);//设置透明度
posted @ 2014-05-26 13:13  加拿大小哥哥  阅读(33800)  评论(0编辑  收藏  举报