Android的按钮按下效果
    package cn.zx.android;  
      
    import android.app.Activity;  
    import android.os.Bundle;  
    import android.view.KeyEvent;  
    import android.view.View;  
    import android.view.View.OnClickListener;  
    import android.view.View.OnKeyListener;  
    import android.widget.Button;  
      
    public class ButtonActivity extends Activity {  
        /** Called when the activity is first created. */  
        private Button btn;  
        @Override  
        public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.main);  
            btn=(Button)this.findViewById(R.id.btn);  
            btn.setOnClickListener(new OnClickListener(){  
      
                @Override  
                public void onClick(View arg0) {  
                    // TODO Auto-generated method stub  
                    System.out.println("btn pressed");  
                }  
                  
            });  
        }  
    }  

布局文件:

<?xml version="1.0" encoding="utf-8"?>  
    <selector xmlns:android="http://schemas.android.com/apk/res/android">  
        <item android:drawable="@drawable/android_pressed"  
              android:state_pressed="true" />  
        <item android:drawable="@drawable/android_focused"  
              android:state_focused="true" />  
        <item android:drawable="@drawable/android_normal" />  
    </selector>  
    <pre class="xml" name="code">    <ImageButton   
            android:layout_width="fill_parent"   
            android:layout_height="wrap_content"  
            android:background="@drawable/ic_tab_artists"  
        /></pre>  
       




阅读更多
个人分类: Android
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Android的按钮按下效果

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭