• ImageButton和Button区别


    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);//设置透明度
     
     
     
     
     
     
     
  • 相关阅读:
    关于C的一些理解
    Linux下/proc目录简介
    python学习链接
    “段寄存器”的故事[转](彻底搞清内存段/elf段/实模式保护模式以及段寄存器)
    内核态与用户态
    bzoj1087: [SCOI2005]互不侵犯King 状压dp
    bzoj1007: [HNOI2008]水平可见直线 单调栈维护凸壳
    bzoj1015: [JSOI2008]星球大战starwar
    bzoj1002: [FJOI2007]轮状病毒 生成树计数
    bzoj1013: [JSOI2008]球形空间产生器sphere
  • 原文地址:https://www.cnblogs.com/tonglingqijie/p/4686417.html
Copyright © 2020-2023  润新知