zoukankan      html  css  js  c++  java
  • android教程之用户界面篇ImageButton

           图片按钮控件的使用跟其他控件的使用大同小异,就是使用整张图片作为响应按钮,而ImageButton中的图片既可以再xml文件中定义,也可以在java文件中定义,还是老规矩,我们直接上代码演示:

    imagebutton.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <!-- android:contentDescription 新版android系统需加上这个属性,要不然会有小警告 -->
        <ImageButton 
            android:id="@+id/imgbt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/imagebutton"/>
        <TextView 
            android:id="@+id/text3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
    

    TestImageButton.java

    public class TestImageButton extends Activity{
    	private ImageButton imgbt;
    	private TextView text3;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		// TODO Auto-generated method stub
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.imagebutton);
    		imgbt=(ImageButton) this.findViewById(R.id.imgbt);
    		imgbt.setImageResource(android.R.drawable.ic_menu_more); //使用系统自带的图片
    		text3=(TextView) this.findViewById(R.id.text3);
    		
    		imgbt.setOnClickListener(new OnClickListener() {
    			
    			@Override
    			public void onClick(View view) {
    				// TODO Auto-generated method stub
    				text3.setText("您点击的图片按钮");
    			}
    		});
    	}
    }

    赶快把你自己的程序运行起来吧

  • 相关阅读:
    php 微信-支付宝APP支付(退款)参数获取
    宝塔面板下安装svn版本管理(Centos)
    获取上传文件浏览器路径
    PHP 自制简易其它网站调用密文加密解密
    获取嵌入的资源
    设计模式02(结构性设计模式)
    人为控制随机概率
    设计模式01(创建性设计模式)
    插件式开发
    使用Word2010直接编辑、发布博客→博客园cnblogs
  • 原文地址:https://www.cnblogs.com/IntelligentBrain/p/5111301.html
Copyright © 2011-2022 走看看